jQuery.noConflict();
(function(b, a) {
    GAG = {};
    a.GAG = GAG;
    GAG.GA = {track: function(g, i, f, h) {
            try {
                if (h == undefined) {
                    h = 1
                }
                _gaq.push(["_trackEvent", g, i, f, h]);
                _gaq.push(["_v._trackEvent", g, i, f, h])
            } catch (j) {
            }
        }};
    if (!a.console) {
        a.console = {log: function() {
            }}
    }
    shortcut = {all_shortcuts: {},add: function(m, f, j) {
            var g = {type: "keydown",propagate: false,disable_in_input: false,target: document,keycode: false};
            if (!j) {
                j = g
            } else {
                for (var e in g) {
                    if (typeof j[e] == "undefined") {
                        j[e] = g[e]
                    }
                }
            }
            var h = j.target;
            if (typeof j.target == "string") {
                h = document.getElementById(j.target)
            }
            var l = this;
            m = m.toLowerCase();
            var i = function(r) {
                r = r || a.event;
                if (j.disable_in_input) {
                    var u;
                    if (r.target) {
                        u = r.target
                    } else {
                        if (r.srcElement) {
                            u = r.srcElement
                        }
                    }
                    if (u.nodeType == 3) {
                        u = u.parentNode
                    }
                    if (u.tagName == "INPUT" || u.tagName == "TEXTAREA") {
                        return
                    }
                }
                if (r.keyCode) {
                    code = r.keyCode
                } else {
                    if (r.which) {
                        code = r.which
                    }
                }
                var s = String.fromCharCode(code);
                if (code == 188) {
                    s = ","
                }
                if (code == 190) {
                    s = "."
                }
                var n = m.split("+");
                var o = 0;
                var q = {"`": "~","1": "!","2": "@","3": "#","4": "$","5": "%","6": "^","7": "&","8": "*","9": "(","0": ")","-": "_","=": "+",";": ":","'": '"',",": "<",".": ">","/": "?","\\": "|"};
                var t = {esc: 27,escape: 27,tab: 9,space: 32,"return": 13,enter: 13,backspace: 8,scrolllock: 145,scroll_lock: 145,scroll: 145,capslock: 20,caps_lock: 20,caps: 20,numlock: 144,num_lock: 144,num: 144,pause: 19,"break": 19,insert: 45,home: 36,"delete": 46,end: 35,pageup: 33,page_up: 33,pu: 33,pagedown: 34,page_down: 34,pd: 34,left: 37,up: 38,right: 39,down: 40,f1: 112,f2: 113,f3: 114,f4: 115,f5: 116,f6: 117,f7: 118,f8: 119,f9: 120,f10: 121,f11: 122,f12: 123};
                var p = {shift: {wanted: false,pressed: false},ctrl: {wanted: false,pressed: false},alt: {wanted: false,pressed: false},meta: {wanted: false,pressed: false}};
                if (r.ctrlKey) {
                    p.ctrl.pressed = true
                }
                if (r.shiftKey) {
                    p.shift.pressed = true
                }
                if (r.altKey) {
                    p.alt.pressed = true
                }
                if (r.metaKey) {
                    p.meta.pressed = true
                }
                for (var v = 0; k = n[v], v < n.length; v++) {
                    if (k == "ctrl" || k == "control") {
                        o++;
                        p.ctrl.wanted = true
                    } else {
                        if (k == "shift") {
                            o++;
                            p.shift.wanted = true
                        } else {
                            if (k == "alt") {
                                o++;
                                p.alt.wanted = true
                            } else {
                                if (k == "meta") {
                                    o++;
                                    p.meta.wanted = true
                                } else {
                                    if (k.length > 1) {
                                        if (t[k] == code) {
                                            o++
                                        }
                                    } else {
                                        if (j.keycode) {
                                            if (j.keycode == code) {
                                                o++
                                            }
                                        } else {
                                            if (s.toLowerCase() == k.toLowerCase()) {
                                                o++
                                            } else {
                                                if (q[s] && r.shiftKey) {
                                                    s = q[s];
                                                    if (s == k) {
                                                        o++
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (o == n.length && p.ctrl.pressed == p.ctrl.wanted && p.shift.pressed == p.shift.wanted && p.alt.pressed == p.alt.wanted && p.meta.pressed == p.meta.wanted) {
                    f(r);
                    if (!j.propagate) {
                        r.cancelBubble = true;
                        r.returnValue = false;
                        if (r.stopPropagation) {
                            r.stopPropagation();
                            r.preventDefault()
                        }
                        return false
                    }
                }
            };
            this.all_shortcuts[m] = {callback: i,target: h,event: j.type};
            if (h.addEventListener) {
                h.addEventListener(j.type, i, false)
            } else {
                if (h.attachEvent) {
                    h.attachEvent("on" + j.type, i)
                } else {
                    h["on" + j.type] = i
                }
            }
        },remove: function(e) {
            e = e.toLowerCase();
            var g = this.all_shortcuts[e];
            delete (this.all_shortcuts[e]);
            if (!g) {
                return
            }
            var i = g.event;
            var h = g.target;
            var f = g.callback;
            if (h.detachEvent) {
                h.detachEvent("on" + i, f)
            } else {
                if (h.removeEventListener) {
                    h.removeEventListener(i, f, false)
                } else {
                    h["on" + i] = false
                }
            }
        }};
    GAG.Utils = {parseJsonString: function(f) {
            try {
                return b.parseJSON(f)
            } catch (g) {
            }
            return {}
        },formatPostLink: function(e) {
            return "http://" + GAG.Page.getDomain() + "/gag/" + e
        },textSearch: function(h, e, g, f) {
            if (typeof f == "undefined") {
                f = {}
            }
            b(h).keyup(function() {
                var i = b(this).val();
                var j = 0;
                b(e).each(function() {
                    var l = -1;
                    var o = b(this).find(g).text();
                    if ((l = o.search(new RegExp(i, "i"))) < 0) {
                        b(this).hide()
                    } else {
                        b(this).show();
                        if (typeof f.highlight != "undefined" && f.highlight) {
                            var n = o.substr(0, l) + "<strong>";
                            var m = o.substr(l, i.length) + "</strong>" + o.substr(l + i.length, o.length);
                            b(this).find(g).html(n + m)
                        }
                        j++
                    }
                })
            })
        },getUrlParam: function(e) {
            return decodeURI((RegExp(e + "=(.+?)(&|$)").exec(location.search) || [, null])[1])
        },formatNumber: function(j, g, m, i) {
            if (typeof g === "undefined") {
                g = 0
            }
            j = (j + "").replace(/[^0-9+\-Ee.]/g, "");
            var f = !isFinite(+j) ? 0 : +j, e = !isFinite(+g) ? 0 : Math.abs(g), p = (typeof i === "undefined") ? "," : i, h = (typeof m === "undefined") ? "." : m, o, l = function(s, r) {
                var q = Math.pow(10, r);
                return "" + Math.round(s * q) / q
            };
            o = (e ? l(f, e) : "" + Math.round(f)).split(".");
            if (o[0].length > 3) {
                o[0] = o[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, p)
            }
            if ((o[1] || "").length < e) {
                o[1] = o[1] || "";
                o[1] += new Array(e - o[1].length + 1).join("0")
            }
            return o.join(h)
        }};
    GAG.Validator = {isValidLoginKey: function(e) {
            return this.isValidUsername(e) || this.isValidEmail(e)
        },isValidUsername: function(e) {
            return e.test("^[0-9a-zA-Z_]{3,15}$")
        },isValidEmail: function(e) {
            return (e.match("^([a-zA-Z0-9._-]+)@([a-zA-Z0-9.-]+)\\.([a-zA-Z]{2,4})$") != null)
        },isValidFullName: function(e) {
            return (b.trim(e).length > 0)
        },isValidPassword: function(f, g, e) {
            var h = true;
            if (g != undefined) {
                if (f.length < g) {
                    h = false
                }
            }
            if (e != undefined) {
                if (f.length > e) {
                    h = false
                }
            }
            if (f.length == 0) {
                h = false
            }
            return h
        },isValidGender: function(e) {
            return e == "F" || e == "M"
        },MONTH_DAYS: [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],isValidDateValues: function(g, h, j) {
            var f = g % 400 == 0 || (g % 100 != 0 && g % 4 == 0);
            this.MONTH_DAYS[1] = f ? 29 : 28;
            var i = (j >= 1 && j <= 31) && (h >= 1 && h <= 12) && (g >= 1900);
            var e = j <= this.MONTH_DAYS[h - 1];
            return i && e
        },isValidPostLink: function(e) {
            var f = new RegExp("^http(s?)://" + GAG.Page.getDomain() + "/gag/([1-9])([0-9]*)(\\?[^ ]*)?$");
            return e.trim().test(f)
        },lookLikeURL: function(e) {
            var f = new RegExp("^http(s?)://");
            return e.trim().test(f)
        }};
    GAG.Response = function() {
        this._isSuccess = false;
        this._keys = {};
        this.setKey(GAG.Response.Constants.RESPONSE_MESSAGE, "")
    };
    GAG.Response.Constants = {RESPONSE_MESSAGE: "RESPONSE_MESSAGE",RESPONSE_CODE: "RESPONSE_CODE",RESPONSE_DATA: "RESPONSE_DATA"};
    GAG.Response.prototype.succeeded = function(e) {
        this._isSuccess = true;
        this.setKey(GAG.Response.Constants.RESPONSE_MESSAGE, e);
        return this
    };
    GAG.Response.prototype.failed = function(e) {
        this._isSuccess = false;
        this.setKey(GAG.Response.Constants.RESPONSE_MESSAGE, e);
        return this
    };
    GAG.Response.prototype.isSuccess = function() {
        return this._isSuccess
    };
    GAG.Response.prototype.setKey = function(e, f) {
        this._keys[e] = f;
        return this
    };
    GAG.Response.prototype.getKey = function(e) {
        return this._keys[e]
    };
    GAG.Response.prototype.setCode = function(e) {
        this.setKey(GAG.Response.Constants.RESPONSE_CODE, e);
        return this
    };
    GAG.Response.prototype.getCode = function() {
        return this.getKey(GAG.Response.Constants.RESPONSE_CODE)
    };
    GAG.Response.prototype.setData = function(e) {
        this.setKey(GAG.Response.Constants.RESPONSE_DATA, e);
        return this
    };
    GAG.Response.prototype.getData = function() {
        return this.getKey(GAG.Response.Constants.RESPONSE_DATA)
    };
    GAG.Response.prototype.setMessage = function(e) {
        this.setKey(GAG.Response.Constants.RESPONSE_MESSAGE, e);
        return this
    };
    GAG.Response.prototype.getMessage = function() {
        return this.getKey(GAG.Response.Constants.RESPONSE_MESSAGE)
    };
    GAG.BaseObject = function() {
        this._namespace = ""
    };
    GAG.BaseObject.prototype.setNamespace = function(e) {
        this._namespace = e
    };
    GAG.BaseObject.prototype.log = function(f, e) {
        console.log(this._namespace + " " + (e ? e + " " : "") + f)
    };
    GAG.BaseObject.prototype.failed = function(e) {
        return (new GAG.Response()).failed(e)
    };
    GAG.BaseObject.prototype.succeeded = function(e) {
        return (new GAG.Response()).succeeded(e)
    };
    GAG.Model = function() {
        this._base = this
    };
    GAG.Model.prototype = new GAG.BaseObject();
    GAG.Model.prototype.getBase = function() {
        return this._base
    };
    GAG.Model.prototype.init = function() {
    };
    GAG.Configs = {_configs: {},init: function() {
        },load: function(e) {
            this._configs = e ? e : {}
        },get: function(f) {
            var g = f.split(".");
            var e = this._configs;
            var h = "";
            while (e && g.length > 0) {
                e = e[g.shift()];
                h = e
            }
            return h
        },Facebook: {init: function() {
            },getAppId: function() {
                return GAG.Configs.get("configs.facebook.app_id")
            },getChannelFile: function() {
                var e = GAG.Page.getProtocol();
                return "//" + GAG.Page.getDomain() + "/static/" + e + "_channel.html"
            }}};
    GAG.State = {fbAsyncInited: false};
    GAG.Page = {_domain: "9gag.com",_backUrl: "",_pageKey: "",init: function() {
            this._domain = GAG.Configs.get("page.domain");
            this._backUrl = GAG.Configs.get("page.back_url");
            this._pageKey = GAG.Configs.get("page.page_key")
        },getProtocol: function() {
            return ("https:" == document.location.protocol) ? "https" : "http"
        },getDomain: function() {
            return this._domain
        },getCookieOptions: function() {
            return {path: "/",expires: 365 * 20}
        },getPageKey: function() {
            return this._pageKey
        },load: function(e) {
            a.location = e
        },preloadImage: function(g) {
            var f = new Image();
            f.src = g;
            var e = document.getElementById("tmp-img");
            if (e) {
                e.appendChild(f)
            }
        },getBackUrl: function() {
            return this._backUrl
        },KEYS: {NEW_VOTE_PAGE: "v",POST_PAGE: "post",LANDING_PAGE: "landing",PROFILE_PAGE: "profile",MEMBER_PAGE: "member",HOT_PAGE: "hot",TRENDING_PAGE: "trending",VOTE_PAGE: "vote",INVITE_FACEBOOK_PAGE: "invite"},isNewVotePage: function() {
            return this._pageKey == this.KEYS.NEW_VOTE_PAGE
        },isPostPage: function() {
            return this._pageKey == this.KEYS.POST_PAGE
        },isLandingPage: function() {
            return this._pageKey == this.KEYS.LANDING_PAGE
        },isListingPage: function() {
            return (jQuery.inArray(this._pageKey, [this.KEYS.HOT_PAGE, this.KEYS.TRENDING_PAGE, this.KEYS.VOTE_PAGE]) >= 0) ? true : false
        },isProfilePage: function() {
            return this._pageKey == this.KEYS.PROFILE_PAGE
        },isMemberPage: function() {
            return this._pageKey == this.KEYS.MEMBER_PAGE
        },isInviteFacebookPage: function() {
            return this._pageKey == this.KEYS.INVITE_FACEBOOK_PAGE
        }};
    GAG.Facebook = {_xfbmlRenderItems: [],_fbInitedCallbacks: [],_getFriendsCallbacks: [],init: function() {
        },asyncInit: function() {
            GAG.State.fbAsyncInited = true;
            this.initApp();
            this.executeRenderQueue();
            this.getFriends()
        },initApp: function() {
            FB.init({appId: GAG.Configs.Facebook.getAppId(),channelUrl: GAG.Configs.Facebook.getChannelFile(),xfbml: false,status: true,cookie: true});
            this._checkFacebookLoginStatus()
        },addInitCallback: function(f, e) {
            GAG.Facebook._fbInitedCallbacks.push({callbackType: f,callback: e})
        },_executeFbInitedCallbacks: function(g) {
            for (var e = 0; e < this._fbInitedCallbacks.length; e++) {
                var f = this._fbInitedCallbacks[e];
                if ((g.indexOf(f.callbackType) !== -1) && (typeof f.callback == "function") && (!this._fbInitedCallbacks[e]["executed"])) {
                    this._fbInitedCallbacks[e]["executed"] = true;
                    f.callback()
                }
            }
        },sessionChangeHandler: function(e) {
            if (!e) {
                return
            }
            if (e.status === "connected") {
                if (e.authResponse) {
                    GAG.Facebook._executeFbInitedCallbacks("connected,logged-in,all")
                }
            } else {
                if (e.status === "not_authorized") {
                    GAG.Facebook._executeFbInitedCallbacks("logged-in,all")
                } else {
                    GAG.Facebook._executeFbInitedCallbacks("logged-out,all")
                }
            }
        },_checkFacebookLoginStatus: function() {
            FB.getLoginStatus(GAG.Facebook.sessionChangeHandler);
            FB.Event.subscribe("auth.authResponseChange", GAG.Facebook.sessionChangeHandler)
        },executeRenderQueue: function() {
            for (var f = 0; f < this._xfbmlRenderItems.length; f++) {
                var e = this._xfbmlRenderItems[f];
                this.parseElement(e.elementId, e.callback)
            }
        },renderElement: function(e, f) {
            if (GAG.State.fbAsyncInited) {
                this.parseElement(e, f)
            } else {
                this._xfbmlRenderItems.push({elementId: e,callback: f})
            }
        },parseElement: function(f, h) {
            try {
                if (h) {
                    FB.XFBML.parse(document.getElementById(f), h)
                } else {
                    FB.XFBML.parse(document.getElementById(f))
                }
            } catch (g) {
            }
        },login: function(e) {
            FB.login(function(f) {
                if (f.authResponse) {
                    if (typeof (e) == "function") {
                        e.call(f)
                    } else {
                        alert("it is not a callback")
                    }
                }
                return f.authResponse
            })
        },openSendDialog: function(g, f, h, i, e) {
            FB.ui({method: "send",name: f,to: g,link: h,desciption: i,picture: e})
        },getFriends: function() {
            if (GAG.Facebook._getFriendsCallbacks.length > 0) {
                FB.getLoginStatus(function(g) {
                    if (g.status === "connected") {
                        for (var h = 0; h < GAG.Facebook._getFriendsCallbacks.length; h++) {
                            try {
                                FB.api("/me/friends", GAG.Facebook._getFriendsCallbacks[h])
                            } catch (j) {
                            }
                        }
                        GAG.Facebook._getFriendsCallbacks = []
                    } else {
                        var f = GAG.Facebook.login(GAG.Facebook.getFriends)
                    }
                })
            }
        },addGetFriendsCallback: function(e) {
            this._getFriendsCallbacks.push(e)
        },getProfilePic: function(f) {
            var e = "https://graph.facebook.com/{{fbid}}/picture?type=square";
            return e.replace("{{fbid}}", f)
        },renderComment: function(e, i, g) {
            var h = this.Plugins.Comments.getElement(g);
            var f = b("#" + e).append(h);
            this.renderElement(e, i)
        },renderLike: function(e, i, g) {
            var h = this.Plugins.Like.getElement(g);
            var f = b("#" + e).html("").append(h);
            this.renderElement(e, i)
        },Plugins: {Comments: {getElement: function(f) {
                    var e = {"class": "fb-comments","data-href": "","data-num-posts": 5,"data-width": 470};
                    f = b.extend(e, f);
                    var h = b("<div/>");
                    for (var g in f) {
                        h.attr(g, f[g])
                    }
                    return h
                }},Like: {getElement: function(f) {
                    var e = {"class": "fb-like","data-href": "","data-layout": "button_count","data-show-faces": "false","data-font": "arial","data-width": 300};
                    f = b.extend(e, f);
                    var h = b("<div/>");
                    for (var g in f) {
                        h.attr(g, f[g])
                    }
                    return h
                }}},Connect: {FB_CONNECT_CALLBACK_URL: "/connect/facebook-callback",INIT_FAILURE_MESSAGE: "Facebook Connect is not enabled, please check if there's any browser plugin blocking the function.",_additionalParams: {},addParam: function(e, f) {
                this._additionalParams[e] = f
            },_getConnectParamsString: function() {
                var f = "";
                var e = 0;
                for (k in this._additionalParams) {
                    f += (e == 0 ? "" : "&") + k + "=" + encodeURIComponent(this._additionalParams[k]);
                    e++
                }
                return f
            },_getConnectUrl: function(f) {
                var e = GAG.Facebook.Connect.FB_CONNECT_CALLBACK_URL;
                e += "?" + this._getConnectParamsString();
                return e
            },connect: function(h) {
                try {
                    if (h == undefined || h == null) {
                        h = "/"
                    }
                    var f = "https://" + GAG.Page.getDomain() + "/connect/facebook";
                    var g = "next=" + encodeURIComponent(h + "&" + this._getConnectParamsString());
                    f += "?" + g;
                    a.location = f
                } catch (i) {
                    if (b.browser.msie && parseInt(b.browser.version, 10) <= 8) {
                    } else {
                    }
                    return
                }
            }}};
    a.fbAsyncInit = function() {
        GAG.Facebook.asyncInit()
    };
    GAG.GPlus = {btnClicked: false,_asyncInited: false,_renderQueue: [],init: function() {
            this._checkAsyncInit()
        },_checkAsyncInit: function() {
            if (typeof gapi !== "undefined") {
                this.asyncInit()
            } else {
                setTimeout(b.proxy(this._checkAsyncInit, this), 100)
            }
        },asyncInit: function() {
            this._asyncInited = true;
            this._executeQueue()
        },renderButton: function(e, g) {
            var f = this._getRenderOptions();
            f.callback = g;
            if (this._asyncInited) {
                gapi.signin.render(e, f)
            } else {
                this._renderQueue.push({domId: e,options: f})
            }
        },_executeQueue: function() {
            while (this._renderQueue.length > 0) {
                var e = this._renderQueue.shift();
                gapi.signin.render(e.domId, e.options)
            }
        },_getRenderOptions: function() {
            var e = {clientid: GAG.Configs.get("configs.gplus.client_id"),cookiepolicy: "single_host_origin",accesstype: "offline",scope: "https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email"};
            var f = GAG.Configs.get("configs.gplus.app_package_name");
            if (f) {
                e.apppackagename = f
            }
            return e
        }};
    a.gplusRender = function() {
    };
    GAG.User = b.extend({}, new GAG.Model(), (function() {
        var e = {_isLoggedIn: null,_user: null};
        return {init: function() {
                e._user = GAG.Configs.get("user")
            },isLoggedIn: function(h, g) {
                if (e._isLoggedIn === null) {
                    e._isLoggedIn = this.getUsername().length > 0
                }
                if (h && !e._isLoggedIn) {
                    var f = "https://" + GAG.Page.getDomain() + "/login";
                    if (g) {
                        f += "?next=" + g
                    }
                    GAG.Page.load(f)
                }
                return e._isLoggedIn
            },getUsername: function() {
                return e._user && e._user.username ? e._user.username : ""
            }}
    })());
    GAG.Login = b.extend({}, new GAG.Model(), {userId: ""});
    GAG.Entry = (function() {
        var e = {API: {REPORT_ENTRY_URI: "/report-post"},init: function() {
            },_isRequesting: false,report: function(j, g, h, l, f) {
                if (!GAG.User.isLoggedIn(true, GAG.Page.getBackUrl())) {
                    return
                }
                if (e._isRequesting) {
                    return
                }
                var m = {entryId: j,type: g,link: h};
                var i = e.API.REPORT_ENTRY_URI;
                b.ajax({type: "POST",url: i,data: m,beforeSend: function() {
                        GAG.Entry._isRequesting = true
                    },complete: function() {
                        GAG.Entry._isRequesting = false
                    },success: function(o) {
                        var n = GAG.Utils.parseJsonString(o);
                        if (n.okay) {
                            l(j)
                        } else {
                            f(j)
                        }
                    },error: function(n) {
                        f(j)
                    }})
            }};
        return {init: e.init,report: e.report}
    })();
    GAG.Vote = b.extend({}, new GAG.Model(), {API: {URL_LIKE: "/vote/like",URL_DISLIKE: "/vote/dislike",URL_UNLIKE: "/vote/unlike"},_requests: {},_isRequesting: false,init: function() {
        },_submitRequest: function(f, h, i, e) {
            if (h === undefined) {
                return
            }
            if (this._isRequesting) {
            }
            var j = {id: h};
            var g = true;
            b.ajax({type: "POST",url: f,data: j,beforeSend: function() {
                    GAG.Vote._isRequesting = true;
                    if (typeof i == "function") {
                        i(h)
                    }
                },complete: function() {
                    GAG.Vote._isRequesting = false
                },success: function(m) {
                    var l = GAG.Utils.parseJsonString(m);
                    if (l.id && l.msg) {
                        if (typeof i == "function") {
                            i(h)
                        }
                    } else {
                        if (typeof e == "function") {
                            e(h)
                        }
                    }
                },error: function(l) {
                    if (typeof e == "function") {
                        e(h)
                    }
                }})
        },like: function(f, g, e) {
            this._submitRequest(this.API.URL_LIKE, f, g, e)
        },unlike: function(f, g, e) {
            this._submitRequest(this.API.URL_UNLIKE, f, g, e)
        },dislike: function(f, g, e) {
            this._submitRequest(this.API.URL_DISLIKE, f, g, e)
        }});
    GAG.Track = {tuvCookie: "_tuv",tuvCookieMax: 100,baseUrl: "http://t.9gag.com",imageUrl: "/img.gif",init: function() {
            var e = GAG.Configs.get("configs.t.domain");
            if (e) {
                GAG.Track.baseUrl = e
            }
        },_saveHistory: function(g, f) {
            var e = f.join(",");
            b.cookie(g, e, {expires: 10000,path: "/",domain: GAG.Configs.get("page.cookie_domain")})
        },_checkUnique: function(i, f, e) {
            if (e.length > 32) {
                var e = b.md5(e)
            }
            var g = b.cookie(i);
            var h = [];
            if (g) {
                h = g.split(",")
            }
            if (h.indexOf(e) == -1) {
                if (h.length >= f) {
                    h.shift()
                }
                h.push(e);
                GAG.Track._saveHistory(i, h);
                return true
            } else {
                return false
            }
            return true
        },uniqueViewed: function(g) {
            var l = "unique-viewed";
            if (typeof g.entry == "undefined") {
                return
            }
            var f = g.entry || "";
            var j = f.split(",");
            var e = [];
            for (var h = 0; h < j.length; h++) {
                if (GAG.Track._checkUnique(GAG.Track.tuvCookie, GAG.Track.tuvCookieMax, j[h])) {
                    e.push(j[h])
                }
            }
            if (j.length > 0 && e.length > 0) {
                g.entry = e.join(",");
                GAG.Track.event(l, "v", g)
            }
        },read: function(e) {
            b.ajax({type: "POST",url: "/read/ids",data: {ids: e.join(",")},dataType: "json",success: function(f) {
                },error: function(f) {
                }})
        },markReadInCookie: function(e) {
            GAG.Track._checkUnique("viewed_ids", GAG.Track.tuvCookieMax, e)
        },page: function() {
            var f = "viewed";
            var e = location.href;
            GAG.Track.event(f, e, {})
        },event: function(j, i, h) {
            var f = h.user ? h.user : GAG.Configs.get("user.id");
            if (!f) {
                f = ""
            }
            var l = {action: j,value: i,ref: "",label: (typeof h.label === "undefined") ? "" : h.label,labelValue: (typeof h.labelValue === "undefined") ? "" : h.labelValue,platform: (typeof h.platform === "undefined") ? "" : h.platform,entry: (typeof h.entry === "undefined") ? "" : h.entry,user: f,view: (typeof h.view === "undefined") ? "" : h.view};
            l.ref = GAG.Track._getQueryStringParam("ref");
            var g = GAG.Track._formatUrl(l);
            var e = new Image();
            e.src = g
        },_getUrl: function() {
            return location.href
        },_getReferrer: function() {
            return document.referrer
        },_getTime: function() {
            var e = new Date();
            var f = new Date(e.getUTCFullYear(), e.getUTCMonth(), e.getUTCDate(), e.getUTCHours(), e.getUTCMinutes(), e.getUTCSeconds());
            var g = Math.round((f).getTime() / 1000);
            return g
        },_getQueryStringParam: function(h) {
            var f = a.location.href;
            var e = f.split(/[\?&]+/);
            for (var g = 0; g < e.length; g++) {
                var j = e[g].split("=");
                if (j[0] == h) {
                    return j[1]
                }
            }
            return ""
        },_formatUrl: function(g) {
            var e = GAG.Track.baseUrl + GAG.Track.imageUrl;
            var j = "";
            var h = [];
            if (g) {
                if (g.action != undefined && g.action != null) {
                    h.push("a=" + encodeURIComponent(g.action))
                }
                if (g.value != undefined && g.value != null) {
                    h.push("v=" + encodeURIComponent(g.value))
                }
                if (g.ref != undefined && g.ref != null) {
                    h.push("ref=" + encodeURIComponent(g.ref))
                }
                if (g.label != undefined && g.label != null) {
                    h.push("lbl=" + encodeURIComponent(g.label))
                }
                if (g.labelValue != undefined && g.labelValue != null) {
                    h.push("lblv=" + encodeURIComponent(g.labelValue))
                }
                if (g.platform != undefined && g.platform != null) {
                    h.push("p=" + encodeURIComponent(g.platform))
                }
                if (g.entry != undefined && g.entry != null) {
                    h.push("e=" + encodeURIComponent(g.entry))
                }
                if (g.user != undefined && g.user != null) {
                    h.push("u=" + encodeURIComponent(g.user))
                }
                if (g.view != undefined && g.view != null) {
                    h.push("w=" + encodeURIComponent(g.view))
                }
            }
            h.push("url=" + encodeURIComponent(GAG.Track._getUrl()));
            h.push("referrer=" + encodeURIComponent(GAG.Track._getReferrer()));
            h.push("t=" + encodeURIComponent(GAG.Track._getTime()));
            for (var f = 0; f < h.length; f++) {
                j += h[f] + "&"
            }
            e += "?" + j;
            return e
        }};
    GAG.Controller = function() {
        this._base = this
    };
    GAG.Controller.prototype = new GAG.BaseObject();
    GAG.Controller.prototype.getBase = function() {
        return this._base
    };
    GAG.Controller.prototype.init = function() {
    };
    GAG.Controller.prototype.onLoad = function() {
    };
    GAG.Controller.prototype.onResize = function() {
    };
    GAG.Controller.prototype.onScroll = function() {
    };
    GAG.Controller.prototype.onDomReady = function() {
    };
    GAG.FacebookController = b.extend({}, new GAG.Controller(), (function() {
        var e = {BADGE_FACEBOOK_RENDER: ".badge_facebook_render",FB_RENDER_PREFIX: "jsid-fb-render",_pushFbElementsToQueue: function() {
                b(e.BADGE_FACEBOOK_RENDER).each(function(f, g) {
                    var h = b(g).attr("id");
                    if (!h) {
                        h = GAG.PageController.getUniqueDomId(GAG.FacebookController.FB_RENDER_PREFIX);
                        b(g).attr("id", h)
                    }
                    GAG.Facebook.renderElement(h)
                })
            },_bindAddToTimelineButtons: function() {
                b(".badge-add-fb-timeline").on("click", function(h) {
                    h.preventDefault();
                    var f = b(this).hasClass("switch_on");
                    if (f) {
                        GAG.FacebookController.enableFbTimelineAck(false);
                        return
                    }
                    var g = "email,publish_actions";
                    try {
                        FB.login(function(i) {
                            var j = i.authResponse ? true : false;
                            GAG.FacebookController.enableFbTimelineAck(j)
                        }, {scope: g})
                    } catch (h) {
                    }
                })
            },};
        return {init: function() {
                e._pushFbElementsToQueue();
                e._bindAddToTimelineButtons()
            },enableFbTimelineAck: function(f) {
                var g = "/member/facebook-timeline";
                var h = {on: f ? "on" : "off",platform: "facebook"};
                if (!f) {
                    g = "/connect/unlink"
                }
                b.ajax({type: "POST",dataType: "json",url: g,data: h,success: function(i) {
                        a.location.reload()
                    }})
            }}
    })());
    GAG.GPlusController = b.extend({}, new GAG.Controller(), {init: function() {
            this._bindElements()
        },_bindProfile: function(e) {
            if (!GAG.GPlus.btnClicked) {
                return
            }
            if (e.access_token) {
                var f = e.code;
                var g = {platform: "google-plus"};
                if (f) {
                    g.code = f
                }
                b.ajax({url: "/connect/social",type: "POST",dataType: "json",data: g,success: function(h) {
                        if (h && h.okay) {
                            a.location.reload()
                        }
                    },error: function(h) {
                        console.log(h)
                    }})
            }
        },_doLogin: function(f) {
            if (!GAG.GPlus.btnClicked) {
                return
            }
            if (f.access_token) {
                var g = f.code;
                var e = "https://" + GAG.Page.getDomain() + "/connect/google-plus-callback?code=" + encodeURIComponent(g);
                a.location.href = e
            }
        },_bindElements: function() {
            GAG.GPlus.renderButton("jsid-gplus-btn-settings", this._bindProfile);
            b(".badge-gplus-connect").each(function(e, g) {
                var f = b(g);
                var h = f.attr("id");
                if (!h) {
                    h = GAG.PageController.getUniqueDomId("gplus");
                    f.attr("id", h)
                }
                GAG.GPlus.renderButton(h, GAG.GPlusController._doLogin)
            })
        }});
    GAG.ShareController = b.extend({}, new GAG.Controller(), (function() {
        var e = {selectors: {CLICK_EVENT_SELECTOR_DELEGATE: "#container",},_openFacebookShareDialog: function(i) {
                i.preventDefault();
                var g = b(this);
                var h = g.attr("data-share");
                var f = "https://www.facebook.com/sharer/sharer.php?u=" + encodeURIComponent(h);
                e._openWindow(f)
            },_openTwitterShareDialog: function(j) {
                j.preventDefault();
                var h = b(this);
                var i = h.attr("data-share");
                var g = h.attr("data-title");
                var f = "https://twitter.com/intent/tweet?via=9GAG&source=tweetbutton&original_referer=" + encodeURIComponent(i) + "&text=" + g + "&url=" + encodeURIComponent(i);
                e._openWindow(f)
            },_openGPlusShareDialog: function(j) {
                j.preventDefault();
                var h = b(this);
                var i = h.attr("data-share");
                var g = h.attr("data-title");
                var f = "https://plus.google.com/share?url=" + encodeURIComponent(i);
                e._openWindow(f)
            },_openPinterestShareDialog: function(l) {
                l.preventDefault();
                var i = b(this);
                var j = i.attr("data-share");
                var h = i.attr("data-img");
                var g = i.attr("data-title");
                var f = "//pinterest.com/pin/create/button/?url=" + encodeURIComponent(j) + "&media=" + encodeURIComponent(h) + "&description=" + g;
                e._openWindow(f)
            },_openWindow: function(j) {
                var g = 640;
                var m = 460;
                var f = a.screen.height / 2 - (m / 2);
                var i = a.screen.width / 2 - (g / 2);
                var l = a.open(j, "Share", "status=1,height=" + m + ",width=" + g + ",top=" + f + ",left=" + i + ",resizable=0")
            },_bindElements: function() {
                b(e.selectors.CLICK_EVENT_SELECTOR_DELEGATE).on("click", ".badge-facebook-share", e._openFacebookShareDialog);
                b(e.selectors.CLICK_EVENT_SELECTOR_DELEGATE).on("click", ".badge-twitter-share", e._openTwitterShareDialog);
                b(e.selectors.CLICK_EVENT_SELECTOR_DELEGATE).on("click", ".badge-gplus-share", e._openGPlusShareDialog);
                b(e.selectors.CLICK_EVENT_SELECTOR_DELEGATE).on("click", ".badge-pinterest-share", e._openPinterestShareDialog)
            }};
        return {init: function() {
                e._bindElements()
            }}
    })());
    GAG.HeadbarController = b.extend({}, new GAG.Controller(), (function() {
        var e = {_bindElements: function() {
                e._bindSearchIcon()
            },_bindSearchIcon: function() {
                var f = b("#jsid-search-icon");
                f.on("click", function(g) {
                    g.preventDefault();
                    e._toggleSearchBar()
                })
            },SLIDE_DURATION: 300,_toggleSearchBar: function() {
                var f = b("#header_searchbar");
                f.slideToggle(e.SLIDE_DURATION)
            }};
        return {init: function() {
                e._bindElements()
            }}
    })());
    GAG.ListController = b.extend({}, new GAG.Controller(), {_scrollDuration: 100,_focusMinimumInViewPortion: 150,_entryReadTimeout: 800,_scrollFaultTolerance: 20,selectors: {LIST_VIEW: ".badge-list-view-element",ENTRY_CONTAINER: ".badge-entry-container",IN_VIEW_ELEMENTS: ".badge-in-view",IN_FOCUS_ELEMENTS: ".badge-in-view-focus",ENTRY_SKIP_LINK: ".badge-item-skip"},customEvents: {IN_FOCUS_SET: "inViewFocusSet",IN_FOCUS_UNSET: "inViewFocusUnset",ENTRY_READ: "entryRead"},init: function() {
            this.bindElements();
            b.proxy(this.handlers.listViewScrollHandler, this)()
        },bindElements: function() {
            this.bindInViewTrackerEvents();
            this.bindSkipLinkEvents();
            this._bindViewHistoryTrackingEvents()
        },handlers: {listViewScrollHandler: function(f) {
                var e = this;
                b(e.selectors.ENTRY_CONTAINER).each(function() {
                    var j = b(this).offset().top;
                    var g = b(this).height();
                    var i = GAG.PageController.getWindowEffectiveScrollTop();
                    var h = b(a).scrollTop() + b(a).height();
                    if (j < h && j + b(this).height() > i) {
                        b(this).addClass("badge-in-view");
                        if (j + g >= i + e._focusMinimumInViewPortion && j + e._focusMinimumInViewPortion <= h) {
                            e._setInViewFocus(this)
                        } else {
                            e._unsetInViewFocus(this)
                        }
                    } else {
                        b(this).removeClass("badge-in-view");
                        e._unsetInViewFocus(this)
                    }
                })
            },skipLinkClickedHandler: function(e) {
                this.scrollToNextEntry(b(e.currentTarget).closest(this.selectors.ENTRY_CONTAINER));
                e.preventDefault()
            }},bindInViewTrackerEvents: function() {
            b(a).on("scroll resize", null, null, b.proxy(this.handlers.listViewScrollHandler, this));
            b("body").on(this.customEvents.IN_FOCUS_SET, this.selectors.ENTRY_CONTAINER, null, b.proxy(function(h) {
                var f = b(h.target);
                var g = setTimeout(b.proxy(function() {
                    b(f).trigger(b.Event(this.customEvents.ENTRY_READ))
                }, this), this._entryReadTimeout);
                b(f).data("entry-read-timeout-object", g)
            }, this));
            b("body").on(this.customEvents.IN_FOCUS_UNSET, this.selectors.ENTRY_CONTAINER, null, b.proxy(function(g) {
                var f = b(g.target);
                clearTimeout(b(f).data("entry-read-timeout-object"))
            }, this))
        },bindSkipLinkEvents: function() {
            b(this.selectors.LIST_VIEW).on("click", this.selectors.ENTRY_SKIP_LINK, null, b.proxy(this.handlers.skipLinkClickedHandler, this))
        },_setInViewFocus: function(e) {
            if (!b(e).hasClass("badge-in-view-focus")) {
                b(e).addClass("badge-in-view-focus");
                b(e).trigger(b.Event(this.customEvents.IN_FOCUS_SET))
            }
        },_unsetInViewFocus: function(e) {
            if (b(e).hasClass("badge-in-view-focus")) {
                b(e).removeClass("badge-in-view-focus");
                b(e).trigger(b.Event(this.customEvents.IN_FOCUS_UNSET))
            }
        },findCurrentlyInViewEntries: function() {
            return b(this.selectors.IN_VIEW_ELEMENTS)
        },findCurrentlyInViewEntry: function() {
            return this.findCurrentlyInViewEntries().first()
        },findCurrentlyInFocusEntries: function() {
            return b(this.selectors.IN_FOCUS_ELEMENTS)
        },findCurrentlyInFocusEntry: function() {
            return this.findCurrentlyInFocusEntries().first()
        },scrollToNextEntry: function(g) {
            if (typeof g == "undefined") {
                g = this.findCurrentlyInViewEntry()
            }
            var i = b(this.selectors.ENTRY_CONTAINER);
            var e = i.index(g);
            var f = e + 1 >= i.length ? e : e + 1;
            var h = b(i[f]);
            if (!h.offset()) {
                return
            }
            b("html,body").animate({scrollTop: h.offset().top - GAG.PageController._topStickyElementHeight}, this._scrollDuration)
        },scrollToPrevEntry: function(h) {
            if (typeof h == "undefined") {
                h = this.findCurrentlyInViewEntry()
            }
            if (b(a).scrollTop() == 0) {
                return
            }
            var i = b(h);
            var f = false;
            if (Math.abs(h.offset().top - GAG.PageController.getWindowEffectiveScrollTop()) < this._scrollFaultTolerance) {
                var j = b(this.selectors.ENTRY_CONTAINER);
                var e = j.index(h);
                var g = e - 1 < 0 ? 0 : e - 1;
                i = b(j[g]);
                f = g == 0
            }
            if (!i.offset()) {
                return
            }
            b("html,body").animate({scrollTop: !f ? (i.offset().top - GAG.PageController._topStickyElementHeight) : 0}, this._scrollDuration)
        },_readIds: {},_readIdsBuffer: [],_readIdsBufferFlushThreshold: 5,_bindViewHistoryTrackingEvents: function() {
            b("body").on(this.customEvents.ENTRY_READ, this.selectors.ENTRY_CONTAINER, null, b.proxy(function(j) {
                var i = b(j.target);
                var h = b(i).data("entry-id");
                var f = GAG.Configs.get("page.page_pool");
                if (!this._readIds[h]) {
                    this._readIds[h] = 1;
                    this._readIdsBuffer.push(h);
                    if (f) {
                        GAG.Track.markReadInCookie(h)
                    }
                    if (this._readIdsBuffer.length >= this._readIdsBufferFlushThreshold) {
                        if (f) {
                            GAG.Track.read(this._readIdsBuffer)
                        }
                        var g = {label: "",labelValue: "",platform: "d",entry: this._readIdsBuffer.join(","),views: "l"};
                        GAG.Track.uniqueViewed(g);
                        this._readIdsBuffer = []
                    }
                }
            }, this))
        }});
    GAG.ListScrollingController = b.extend({}, new GAG.Controller(), {_isLoading: false,_listViewElement: null,_bottomReached: false,_loadCountMax: 20,_loadedCount: 1,_disableAutoHiding: false,selectors: {LOAD_MORE_BUTTON: ".badge-load-more-post",ENTRY_LIST_CONTAINER: ".badge-entry-collection",ENTRY_CONTAINER: ".badge-entry-container",ENTRY_LIST_VIEW: ".badge-list-view-element"},init: function() {
            this._listViewElement = b(this.selectors.ENTRY_LIST_VIEW);
            if (navigator.userAgent.match(/(iPhone|iPod|iPad)/i)) {
                this._disableAutoHiding = true
            } else {
                if (GAG.Page.isPostPage()) {
                    this._disableAutoHiding = true
                }
            }
            this.bindElements()
        },bindElements: function() {
            this.bindScrollEvents();
            this.bindLastEntryInFocus()
        },handlers: {windowScrollHandler: function() {
                b.proxy(this.handlers.loadMoreScrollHandler, this)();
                if (!this._disableAutoHiding) {
                    b.proxy(this.handlers.autoHidingScrollHandler, this)()
                }
            },loadMoreScrollHandler: function() {
                var e = b(a).height();
                if (b(a).scrollTop() + e >= b(document).height() - e * 3) {
                    this.loadMorePosts()
                }
            },loadMoreLastEntryFocusHandler: function(g) {
                var f = b(g.target);
                if (b(this.selectors.ENTRY_CONTAINER).last().is(f)) {
                    this.loadMorePosts()
                }
            },autoHidingScrollHandler: function() {
                var f = b(a).height();
                var e = GAG.PageController.getWindowEffectiveScrollTop();
                b(this.selectors.ENTRY_CONTAINER).each(function() {
                    var g = b(this);
                    var j = g.height();
                    var m = g.offset();
                    var l = m.top;
                    var i = m.top + j;
                    if (!g.hasClass("badge-in-view") && (i < e - f * 3 - j || l > e + f * 4 + j)) {
                        if (g.html() != "") {
                            g.data("stored-html", g.html());
                            g.css("min-height", j + "px");
                            g.empty()
                        }
                    } else {
                        if (g.data("stored-html") != null) {
                            g.html(g.data("stored-html"));
                            g.data("stored-html", null)
                        }
                    }
                })
            },loadMoreAjaxHandler: function(j) {
                if (!j.okay) {
                    return
                }
                var e = "";
                for (var f = 0; f < j.ids.length; f++) {
                    var l = j.ids[f];
                    if (b("#jsid-entry-entity-" + l).length == 0) {
                        e += j.items[l]
                    }
                }
                var g = this.findLastEntryElement();
                b(g).append(e);
                GAG.GA.track("load-more", GAG.Configs.get("page.page_list"), "load-" + this._loadedCount);
                this._loadedCount++;
                var h = b(this.selectors.LOAD_MORE_BUTTON);
                if (this._loadedCount < this._loadCountMax) {
                    if (j.loadMoreUrl != "") {
                        h.prop("href", j.loadMoreUrl);
                        h.text(h.data("original-text"));
                        h.data("original-text", "");
                        h.removeClass("spin")
                    } else {
                        h.removeAttr("href");
                        h.text("No more posts");
                        h.removeClass("spin").addClass("end");
                        this._bottomReached = true
                    }
                } else {
                    h.text("I want more fun");
                    h.prop("href", j.loadMoreUrl);
                    h.removeClass("spin").addClass("blue");
                    this._bottomReached = true
                }
                this._isLoading = false
            }},loadMorePosts: function() {
            if (this._isLoading || this._bottomReached) {
                return
            }
            var g = b(this.selectors.LOAD_MORE_BUTTON);
            g.data("original-text", g.text());
            g.text(g.data("loading-text"));
            g.addClass("spin");
            var f = g.prop("href");
            this._isLoading = true;
            if (typeof f != "undefined" && f != "") {
                if (navigator.userAgent.match(/(iPhone|iPod|iPad)/i)) {
                    var e = new XMLHttpRequest();
                    e.open("GET", f, true);
                    e.setRequestHeader("Accept", "application/json, text/javascript, */*; q=0.01");
                    e.setRequestHeader("X-Requested-With", "XMLHttpRequest");
                    e.onreadystatechange = b.proxy(function() {
                        if (e.readyState == 4 && e.status == 200) {
                            var h = jQuery.parseJSON(e.responseText);
                            console.log("loading more success");
                            this.handlers.loadMoreAjaxHandler.call(this, h)
                        } else {
                            if (e.readyState == 4) {
                                console.log("loading more error")
                            }
                        }
                    }, this);
                    e.send()
                } else {
                    b.getJSON(f, null, b.proxy(this.handlers.loadMoreAjaxHandler, this))
                }
            }
        },findLastEntryElement: function() {
            return this._listViewElement.find(this.selectors.ENTRY_LIST_CONTAINER).last();
            return this._listViewElement.find(this.selectors.ENTRY_CONTAINER).last()
        },bindScrollEvents: function() {
            b(a).scroll(b.proxy(this.handlers.windowScrollHandler, this))
        },bindLastEntryInFocus: function() {
            b("body").on(GAG.ListController.customEvents.IN_FOCUS_SET, this.selectors.ENTRY_CONTAINER, null, b.proxy(this.handlers.loadMoreLastEntryFocusHandler, this))
        }});
    GAG.PostController = b.extend({}, new GAG.Controller(), {_entryStickyElementMarginTop: 20,_entryStickyElementMarginTopProfile: 20,_reportInProgress: false,_voteUp: "good",_voteDown: "meh",_fastInitLoad: true,init: function() {
            this.bindElements();
            this.renderMainPostComment();
            this.renderMainPostLike();
            this.renderPostFooterLike()
        },selectors: {CONTAINER: "div#container",ENTRY_CONTAINER: ".badge-entry-container",ENTRY_ENTITY: ".badge-entry-entity",ENTRY_MAIN_POST_COMMENT_ID: "jsid-main-post-facebook-comment-plugin",ENTRY_MAIN_POST_LIKE_ID: "jsid-main-post-facebook-like-plugin",ENTRY_POST_FOOTER_LIKE_ID: "jsid-footer-facebook-like-plugin",ENTRY_STICKY_ELEMENTS: ".badge-entry-sticky",ENTRY_STICKY_ELEMENTS_SHADOW: ".badge-entry-sticky-shadow",ENTRY_SECONDARY_LINKS: ".badge-entry-secondary-links",ENTRY_SECONDARY_LINKS_AUTOHIDE: ".badge-entry-secondary-links.badge-autohide",ENTRY_TITLE: ".badge-item-title",ENTRY_IMG: ".badge-item-img",ENTRY_LOVE_COUNT: ".badge-item-love-count",ENTRY_COMMENT_COUNT: ".badge-item-comment-count",ENTRY_SHARE_COUNT: ".badge-item-share-count",ENTRY_SHARE: ".badge-item-share",ENTRY_SHARE_MENU: ".badge-item-share-menu",ENTRY_FB_SHARE: ".badge-facebook-share",ENTRY_TW_SHARE: ".badge-twitter-share",ENTRY_GPLUS_SHARE: ".badge-gplus-share",ENTRY_PIN_SHARE: ".badge-pinterest-share",ENTRY_EMAIL_SHARE: ".badge-email-share",ENTRY_NSFW_COVER: ".badge-nsfw-entry-cover",ENTRY_VIDEO_CONTAINER: ".badge-video-container",ENTRY_VIDEO_COVER: ".badge-video-cover",ENTRY_ANIMATED_COVER: ".badge-animated-cover",ENTRY_ANIMATED_CONTAINER_ANIMATED: ".badge-animated-container-animated",ENTRY_ANIMATED_CONTAINER_STATIC: ".badge-animated-container-static",ENTRY_NEXT_POST_ENTRY: ".badge-next-post-entry",ENTRY_PREV_POST_ENTRY: ".badge-prev-post-entry",ENTRY_POST_GRID_ENTRY: ".badge-post-grid-entry",ENTRY_CONTENT: ".badge-entry-content",ENTRY_INFO: ".badge-entry-info",ENTRY_UPVOTE_BUTTON: ".badge-item-vote-up",ENTRY_DOWNVOTE_BUTTON: ".badge-item-vote-down",ENTRY_COMMENT_BUTTON: ".badge-item-comment",ENTRY_VOTE_CONTAINER: ".badge-item-vote-container",ENTRY_POST_ZOOM: ".badge-post-zoom",ENTRY_POST_CONTAINER: ".badge-post-container",ENTRY_EXPAND_BTN: ".badge-expand-post",MODAL_POST_ZOOM_CONTAINER: "#jsid-modal-post-zoom",SEARCH_ENTRY_ENTITY: ".badge-search-entry-entity",MODAL_REPORT_CONTAINER: ".badge-overlay-report",MODAL_REPORT_TYPE: "input[name=radio-report]",MODAL_REPORT_SUBMIT: ".badge-report-submit-btn",REPORT_LINK: ".badge-item-report",POST_DOWNLOAD_FOOTER: "badge-download-footer",POST_SOCIAL_FOOTER: "badge-social-footer",GROUP_TW_SHARE: "twitter-post-share",GROUP_GPLUS_SHARE: "gplus-post-share"},bindElements: function() {
            this.bindVoteUpElements();
            this.bindVoteDownElements();
            this.bindCommentElements();
            this.bindShareElements();
            this.bindReportElements();
            this.bindEntryCoverElements();
            this.bindShowHideReportLinkEvents();
            this.bindStickyEntryBars();
            this.bindZoomElements();
            this._bindEntryTrackingEvents();
            this.bindExpandElements();
            this.bindSearchResultElements();
            this.bindFastElements()
        },_fastItems: null,_fastEntryIds: [],_fastCurrentEntryKey: null,_fastForwardDirection: true,_fastTriggerLoadThreshold: 6,_fastPostGridSize: 6,_fastTimer: null,_fastReloadAdsThreshold: 5,_fastReloadAdsCount: 1,_fastSkipBackward: [],_fastSkipForward: [],initLoadFastEntries: function() {
            var e = GAG.Configs.get("data");
            this._fastCurrentEntryKey = b(this.selectors.ENTRY_ENTITY).data("entry-id");
            if (e.fast_entries != null) {
                this.extractFastEntries(e.fast_entries)
            }
            var f = GAG.Configs.get("configs").replace_post_url;
            if (f) {
                GAG.PostController.updatePostUrl(f)
            }
        },getFastEntriesJson: function(e) {
            var f = "next";
            if (!this._fastForwardDirection) {
                var f = "prev"
            }
            e = e + "?direction=" + f;
            if (GAG.Configs.get("configs").from_section) {
                e += "&sc=1"
            }
            b.getJSON(e, null, b.proxy(this.extractFastEntries, this))
        },extractFastEntries: function(h) {
            if (!h.okay) {
                return
            }
            if (this._fastItems == null) {
                this._fastItems = h.items
            } else {
                b.extend(this._fastItems, h.items)
            }
            var f = h.entryIds;
            if (!this._fastForwardDirection) {
                f.reverse()
            }
            var e = 0;
            for (var g = 0; g < f.length; g++) {
                if (b.inArray(f[g], this._fastEntryIds) < 0) {
                    if (this._fastForwardDirection) {
                        this._fastEntryIds.push(f[g])
                    } else {
                        this._fastEntryIds.unshift(f[g])
                    }
                    e++;
                    this.renderPostGrid(this._fastItems[f[g]])
                }
            }
            if (f.length > 0 && e == 0) {
                if (this._fastForwardDirection) {
                    this._fastSkipForward.push(h.entryIds[0])
                } else {
                    this._fastSkipBackward.push(h.entryIds[0])
                }
            }
        },fastEntriesMapElements: function(g, e) {
            if (this._fastItems[g] != null) {
                var f = this._fastItems[g];
                this.mapPostContent(f);
                if (b(this.selectors.ENTRY_POST_GRID_ENTRY + "[data-entry-key=" + g + "]:visible").length) {
                    b(this.selectors.ENTRY_POST_GRID_ENTRY).removeClass("selected");
                    b(this.selectors.ENTRY_POST_GRID_ENTRY + "[data-entry-key=" + g + "]").addClass("selected")
                } else {
                    this.refreshPostGrid()
                }
                if (this._fastReloadAdsCount >= this._fastReloadAdsThreshold) {
                    googletag.pubads().refresh();
                    this._fastReloadAdsCount = 1
                } else {
                    this._fastReloadAdsCount++
                }
            } else {
                a.location.href = e
            }
        },refreshPostGrid: function() {
            var j = this._fastCurrentEntryKey;
            var e = b.makeArray(this._fastEntryIds);
            var g = b.inArray(this._fastCurrentEntryKey, e);
            b(this.selectors.ENTRY_POST_GRID_ENTRY).parent().addClass("hide");
            b(this.selectors.ENTRY_POST_GRID_ENTRY).removeClass("selected");
            if (this._fastForwardDirection) {
                for (var h = g; h < g + this._fastPostGridSize; h++) {
                    var f = e[h];
                    b(this.selectors.ENTRY_POST_GRID_ENTRY + "[data-entry-key=" + f + "]").parent().removeClass("hide")
                }
            } else {
                if (g < this._fastPostGridSize) {
                    g = this._fastPostGridSize - 1
                }
                for (var h = g; h >= g - this._fastPostGridSize + 1; h--) {
                    var f = e[h];
                    b(this.selectors.ENTRY_POST_GRID_ENTRY + "[data-entry-key=" + f + "]").parent().removeClass("hide")
                }
            }
            b(this.selectors.ENTRY_POST_GRID_ENTRY + "[data-entry-key=" + j + "]").addClass("selected")
        },renderPostGrid: function(i) {
            if (b(this.selectors.ENTRY_POST_GRID_ENTRY + "[data-entry-key=" + i.entryId + "]").length <= 0) {
                var g = b('<li class="hide"></li>');
                var h = b('<a class="badge-fast-entry badge-post-grid-entry" data-entry-key="" href=""></a>');
                var e = b("<img>");
                h.attr("data-entry-key", i.entryId);
                h.attr("href", i.entryRelativeUrl);
                var f = "";
                if (i.entryType == "nsfw") {
                    f = i.thumbnailUrl
                } else {
                    if (i.entryType == "video") {
                        f = i.thumbnailUrl
                    } else {
                        f = i.fbThumbnailUrl
                    }
                }
                e.attr("src", f);
                e.attr("alt", i.title);
                h.append(e);
                g.append(h);
                if (this._fastForwardDirection) {
                    b(".badge-post-grid").append(g)
                } else {
                    b(".badge-post-grid").prepend(g)
                }
            }
        },bindFastElements: function() {
            if (!GAG.Page.isPostPage()) {
                return
            }
            this.initLoadFastEntries();
            b(this.selectors.CONTAINER).on("click", ".badge-fast-entry", b.proxy(function(m) {
                m.preventDefault();
                var n = b(m.currentTarget);
                if (n.hasClass("disabled")) {
                    return
                }
                var o = n.data("entry-key");
                var p = n.attr("href");
                var i = "";
                if (n.hasClass("badge-next-post-entry")) {
                    i = "NEXT_ENTRY";
                    this._fastForwardDirection = true
                } else {
                    if (n.hasClass("badge-prev-post-entry")) {
                        i = "PREV_ENTRY";
                        this._fastForwardDirection = false
                    } else {
                        i = "GRID_ENTRY"
                    }
                }
                this._fastCurrentEntryKey = o;
                if (p) {
                    this.fastEntriesMapElements(o, p);
                    this.replacePostUrl(o);
                    var l = b.inArray(this._fastCurrentEntryKey, this._fastEntryIds);
                    var j = this._fastTriggerLoadThreshold;
                    var h = this._fastEntryIds.length - this._fastTriggerLoadThreshold;
                    var g = b.makeArray(this._fastEntryIds);
                    if (!this._fastForwardDirection && l <= j) {
                        var q = g[1];
                        if (b.inArray(q, this._fastSkipBackward) < 0) {
                            p = b(this.selectors.ENTRY_POST_GRID_ENTRY + "[data-entry-key=" + q + "]").attr("href");
                            this.getFastEntriesJson(p)
                        }
                    } else {
                        if (this._fastForwardDirection && l >= h) {
                            var f = g[g.length - 2];
                            if (b.inArray(f, this._fastSkipForward) < 0) {
                                p = b(this.selectors.ENTRY_POST_GRID_ENTRY + "[data-entry-key=" + f + "]").attr("href");
                                this.getFastEntriesJson(p)
                            }
                        }
                    }
                    GAG.GA.track("fast-entry", i, GAG.Page.getPageKey());
                    GAG.Track.event("viewed", p, {})
                }
            }, this));
            if (GAG.Page.isPostPage()) {
                a.onpopstate = b.proxy(function(i) {
                    var g = a.location.href;
                    var f = g.split("/");
                    if (jQuery.inArray("gag", f) >= 0) {
                        if (!this._fastInitLoad) {
                            var h = f[f.length - 1];
                            this.fastEntriesMapElements(h, g)
                        } else {
                            this._fastInitLoad = false
                        }
                    }
                }, this)
            }
        },mapPostContent: function(l) {
            b("html, body").animate({scrollTop: 0}, 0);
            var h = b(this.selectors.ENTRY_ENTITY);
            var g = b.inArray(l.entryId, this._fastEntryIds);
            h.removeData("entry-id");
            h.removeData("entry-thumbnail-url");
            h.removeData("entry-url");
            h.removeData("entry-votes");
            h.removeData("entry-comments");
            h.attr("id", "jsid-entry-entity-" + l.entryId);
            h.data("entry-id", l.entryId);
            h.data("entry-thumbnail-url", l.thumbnailUrl);
            h.data("entry-url", l.entryUrl);
            h.data("entry-votes", l.votes);
            h.data("entry-comments", l.comments);
            b(this.selectors.ENTRY_TITLE).text(l.title);
            b(this.selectors.ENTRY_LOVE_COUNT).attr("id", "love-count-" + l.entryId);
            b(this.selectors.ENTRY_LOVE_COUNT).text(GAG.Utils.formatNumber(l.votes));
            b(this.selectors.ENTRY_COMMENT_COUNT).text(l.comments);
            b(this.selectors.ENTRY_SHARE).attr("data-entry-id", l.entryId);
            b(this.selectors.ENTRY_SHARE_MENU).attr("id", "share-menu-" + l.entryId);
            b(this.selectors.ENTRY_CONTENT).html(l.entryContent);
            if (l.currentVote == 1) {
                this.handlers.likeHandler(l.entryId)
            } else {
                if (l.currentVote == -1) {
                    this.handlers.dislikeHandler(l.entryId)
                } else {
                    this.handlers.unlikeHandler(l.entryId)
                }
            }
            b(this.selectors.ENTRY_INFO).html(l.entryInfo);
            var f = this._fastItems[this._fastEntryIds[g + 1]];
            b(this.selectors.ENTRY_NEXT_POST_ENTRY).removeData("entry-key");
            if (typeof f != "undefined") {
                b(this.selectors.ENTRY_NEXT_POST_ENTRY).removeClass("disabled");
                b(this.selectors.ENTRY_NEXT_POST_ENTRY).data("entry-key", f.entryId);
                b(this.selectors.ENTRY_NEXT_POST_ENTRY).attr("href", f.entryRelativeUrl)
            } else {
                b(this.selectors.ENTRY_NEXT_POST_ENTRY).addClass("disabled");
                b(this.selectors.ENTRY_NEXT_POST_ENTRY).attr("href", "")
            }
            var i = this._fastItems[this._fastEntryIds[g - 1]];
            b(this.selectors.ENTRY_PREV_POST_ENTRY).removeData("entry-key");
            if (typeof i != "undefined") {
                b(this.selectors.ENTRY_PREV_POST_ENTRY).removeClass("disabled");
                b(this.selectors.ENTRY_PREV_POST_ENTRY).data("entry-key", i.entryId);
                b(this.selectors.ENTRY_PREV_POST_ENTRY).attr("href", i.entryRelativeUrl)
            } else {
                b(this.selectors.ENTRY_PREV_POST_ENTRY).addClass("disabled");
                b(this.selectors.ENTRY_PREV_POST_ENTRY).attr("href", "")
            }
            b("title").text("9GAG - " + l.title);
            b("link[rel=image_src]").attr("href", l.entryUrl);
            b("link[rel=canonical]").attr("href", l.entryUrl);
            b("meta[name=title]").attr("href", l.title);
            b(this.selectors.ENTRY_SHARE_COUNT).text(l.totalShares);
            b(this.selectors.ENTRY_FB_SHARE).removeAttr("data-track").attr("data-track", l.fbTrack);
            b(this.selectors.ENTRY_FB_SHARE).removeAttr("data-evt").attr("data-evt", l.fbEvt);
            b(this.selectors.ENTRY_FB_SHARE).removeAttr("data-share").attr("data-share", l.fbShare);
            b(this.selectors.ENTRY_TW_SHARE).removeAttr("data-track").attr("data-track", l.twTrack);
            b(this.selectors.ENTRY_TW_SHARE).removeAttr("data-evt").attr("data-evt", l.twEvt);
            b(this.selectors.ENTRY_TW_SHARE).removeAttr("data-title").attr("data-title", l.twTitle);
            b(this.selectors.ENTRY_TW_SHARE).removeAttr("data-share").attr("data-share", l.twShare);
            b(this.selectors.ENTRY_GPLUS_SHARE).removeAttr("data-track").attr("data-track", l.gPlusTrack);
            b(this.selectors.ENTRY_GPLUS_SHARE).removeAttr("data-evt").attr("data-evt", l.gPlusEvt);
            b(this.selectors.ENTRY_GPLUS_SHARE).removeAttr("data-share").attr("data-share", l.gPlusShare);
            b(this.selectors.ENTRY_PIN_SHARE).removeAttr("data-track").attr("data-track", l.pinTrack);
            b(this.selectors.ENTRY_PIN_SHARE).removeAttr("data-evt").attr("data-evt", l.pinEvt);
            b(this.selectors.ENTRY_PIN_SHARE).removeAttr("data-title").attr("data-title", l.pinTitle);
            b(this.selectors.ENTRY_PIN_SHARE).removeAttr("data-share").attr("data-share", l.pinShare);
            b(this.selectors.ENTRY_PIN_SHARE).removeAttr("data-img").attr("data-img", l.pinImg);
            b(this.selectors.ENTRY_EMAIL_SHARE).attr("href", l.emailHref);
            b(this.selectors.ENTRY_EMAIL_SHARE).removeAttr("data-track").attr("data-track", l.emailTrack);
            b(this.selectors.ENTRY_EMAIL_SHARE).removeAttr("data-evt").attr("data-evt", l.emailEvt);
            b("#" + this.selectors.ENTRY_MAIN_POST_LIKE_ID).html("");
            b("#" + this.selectors.ENTRY_MAIN_POST_LIKE_ID).removeData("href").data("href", l.entryUrl);
            this.renderMainPostLike();
            if (l.commentSys) {
                b(".badge-comment").removeAttr("data-href").attr("data-href", l.entryUrl);
                a.CS2.load(l.entryUrl);
                b("#" + this.selectors.ENTRY_MAIN_POST_COMMENT_ID).hide();
                b(".badge-comment").show()
            } else {
                b("#" + this.selectors.ENTRY_MAIN_POST_COMMENT_ID).html("");
                b("#" + this.selectors.ENTRY_MAIN_POST_COMMENT_ID).removeData("href").data("href", l.entryUrl);
                this.renderMainPostComment();
                b(".badge-comment").hide();
                b("#" + this.selectors.ENTRY_MAIN_POST_COMMENT_ID).show()
            }
            var j = l.group;
            if (Math.floor(Math.random() * 2) || !j.twitterUsername || !j.facebookUrl) {
                b("." + this.selectors.POST_DOWNLOAD_FOOTER).show();
                b("." + this.selectors.POST_SOCIAL_FOOTER).hide()
            } else {
                b("." + this.selectors.POST_SOCIAL_FOOTER).show();
                b("." + this.selectors.POST_DOWNLOAD_FOOTER).hide();
                b(".social-list").removeClass("col-2 col-3").addClass(j.googlePlusURL ? "col-3" : "col-2");
                if (j.googlePlusURL) {
                    b(".badge-google-plus-column").show()
                } else {
                    b(".badge-google-plus-column").hide()
                }
                b("#" + this.selectors.ENTRY_POST_FOOTER_LIKE_ID).html("").removeData("href").data("href", j.facebookUrl);
                this.renderPostFooterLike();
                b(".badge-social-footer h3").html("Follow 9GAG " + (j.name === "" ? "" : j.name + " ") + "to get updates");
                var e = b("#" + this.selectors.GROUP_TW_SHARE);
                e.html('<a href="https://twitter.com/' + j.twitterUsername + '" class="twitter-follow-button" data-show-count="false" data-show-screen-name="true"></a>');
                twttr.widgets.load(e.get(0));
                if (j.googlePlusURL) {
                    e.parent().removeClass("last")
                } else {
                    e.parent().addClass("last")
                }
                b("#" + this.selectors.GROUP_GPLUS_SHARE).html('<div id="google-group-share"></div>');
                gapi.follow.render("google-group-share", {href: j.googlePlusURL,annotation: "none",rel: "publisher","class": "g-follow"});
                b("#google-share").addClass("g-follow")
            }
            if (l.entryAdminMeta != "undefined") {
                b("#jsid-admin-meta").html(l.entryAdminMeta)
            }
        },renderMainPostComment: function() {
            var e = b("#" + this.selectors.ENTRY_MAIN_POST_COMMENT_ID).data("href");
            GAG.Facebook.renderComment(this.selectors.ENTRY_MAIN_POST_COMMENT_ID, function() {
            }, {"data-href": e,"data-num-posts": 10,"data-width": 600})
        },renderMainPostLike: function(e) {
            var e = b("#" + this.selectors.ENTRY_MAIN_POST_LIKE_ID).data("href");
            GAG.Facebook.renderLike(this.selectors.ENTRY_MAIN_POST_LIKE_ID, function() {
            }, {"data-href": e})
        },renderPostFooterLike: function() {
            var e = b("#" + this.selectors.ENTRY_POST_FOOTER_LIKE_ID).data("href");
            GAG.Facebook.renderLike(this.selectors.ENTRY_POST_FOOTER_LIKE_ID, function() {
            }, {"data-href": e})
        },handlers: {likeHandler: function(g) {
                var e = b("#jsid-entry-entity-" + g);
                var f = e.find(GAG.PostController.selectors.ENTRY_VOTE_CONTAINER);
                f.removeClass(GAG.PostController._voteDown);
                f.addClass(GAG.PostController._voteUp);
                GAG.PostController.updateFastItem(g, "currentVote", 1)
            },dislikeHandler: function(g) {
                var e = b("#jsid-entry-entity-" + g);
                var f = e.find(GAG.PostController.selectors.ENTRY_VOTE_CONTAINER);
                f.removeClass(GAG.PostController._voteUp);
                f.addClass(GAG.PostController._voteDown);
                GAG.PostController.updateFastItem(g, "currentVote", -1)
            },unlikeHandler: function(g) {
                var e = b("#jsid-entry-entity-" + g);
                var f = e.find(GAG.PostController.selectors.ENTRY_VOTE_CONTAINER);
                f.removeClass(GAG.PostController._voteDown);
                f.removeClass(GAG.PostController._voteUp);
                GAG.PostController.updateFastItem(g, "currentVote", 0)
            },reportHandler: function(e) {
                if (!GAG.User.isLoggedIn()) {
                    e.preventDefault();
                    GAG.AccountController.presentSignupForm();
                    return
                }
                b(this.selectors.MODAL_REPORT_CONTAINER).data("entry-id", b(e.currentTarget).closest(this.selectors.ENTRY_ENTITY).data("entry-id"));
                GAG.OverlayController.showOverlay(GAG.OverlayController.selectors.OVERLAY_COMPONENT_REPORT)
            },reportSubmitHandler: function(h) {
                if (!this._reportInProgress) {
                    this._reportInProgress = true;
                    var l = b(h.currentTarget);
                    var j = b(this.selectors.MODAL_REPORT_CONTAINER);
                    var i = j.data("entry-id");
                    var e = b(this.selectors.MODAL_REPORT_TYPE + ":checked", j);
                    var f = e.val();
                    var g = b("#jsid-repost-link").val();
                    l.data("text-normal", l.val());
                    l.val(l.data("text-loading"));
                    GAG.Entry.report(i, f, g, b.proxy(function() {
                        l.val(l.data("text-normal"));
                        GAG.OverlayController.hideOverlay(GAG.OverlayController.selectors.OVERLAY_COMPONENT_REPORT);
                        e.prop("checked", false);
                        this._reportInProgress = false
                    }, this), b.proxy(function() {
                        l.val(l.data("text-normal"));
                        alert("Something went wrong, please try again");
                        this._reportInProgress = false
                    }, this))
                }
            },entryMouseOverShowSecondaryLinkHandler: function(e) {
                b(e.currentTarget).find(this.selectors.ENTRY_SECONDARY_LINKS_AUTOHIDE).removeClass("hide")
            },entryMouseOutHideSecondaryLinkHandler: function(e) {
                b(e.currentTarget).find(this.selectors.ENTRY_SECONDARY_LINKS_AUTOHIDE).addClass("hide")
            },entryStickElementHandler: function(f) {
                var e = this;
                b(e.selectors.ENTRY_STICKY_ELEMENTS).each(function() {
                    var i = b(this).closest(e.selectors.ENTRY_CONTAINER);
                    var j = b(this).closest(e.selectors.ENTRY_STICKY_ELEMENTS_SHADOW);
                    var g = j.offset().top;
                    var h = b(this).height() || b(this).outerHeight();
                    if (g - e._entryStickyElementMarginTop >= GAG.PageController.getWindowEffectiveScrollTop()) {
                        b(this).css("position", "relative");
                        b(this).css("top", "");
                        b(this).css("z-index", 1)
                    } else {
                        if (g - e._entryStickyElementMarginTop < GAG.PageController.getWindowEffectiveScrollTop() && i.offset().top + i.height() + parseFloat(i.css("padding-top")) - h - e._entryStickyElementMarginTop > GAG.PageController.getWindowEffectiveScrollTop()) {
                            b(this).css("position", "fixed");
                            b(this).css("top", (GAG.PageController._topStickyElementHeight + e._entryStickyElementMarginTop) + "px");
                            b(this).css("z-index", 2)
                        } else {
                            b(this).css("position", "relative");
                            b(this).css("top", (i.height() + parseFloat(i.css("padding-top")) - (g - i.offset().top) - h) + "px");
                            b(this).css("z-index", 2)
                        }
                    }
                })
            }},onVoteUp: function(m) {
            var h = b(m.currentTarget);
            var j = h.closest(this.selectors.ENTRY_ENTITY).data("entry-id");
            var l = h.closest(this.selectors.ENTRY_ENTITY).data("entry-url");
            var g = h.closest(this.selectors.ENTRY_VOTE_CONTAINER);
            var f = this.getLoveCounter(j);
            if (GAG.PageController.ensureLoggedIn(l)) {
                var i = g.hasClass(this._voteUp);
                if (g.hasClass(this._voteDown)) {
                    this.addLoveCount(j)
                }
                if (i) {
                    GAG.Vote.unlike(j, function() {
                    }, function() {
                    });
                    this.minusLoveCount(j);
                    this.handlers.unlikeHandler(j);
                    f.removeClass("green").removeClass("red")
                } else {
                    GAG.Vote.like(j, function() {
                    }, function() {
                    });
                    this.addLoveCount(j);
                    this.handlers.likeHandler(j);
                    f.removeClass("red").addClass("green")
                }
            }
        },onVoteDown: function(m) {
            var h = b(m.currentTarget);
            var j = h.closest(this.selectors.ENTRY_ENTITY).data("entry-id");
            var l = h.closest(this.selectors.ENTRY_ENTITY).data("entry-url");
            var g = h.closest(this.selectors.ENTRY_VOTE_CONTAINER);
            var f = this.getLoveCounter(j);
            if (GAG.PageController.ensureLoggedIn(l)) {
                var i = g.hasClass(this._voteDown);
                if (g.hasClass(this._voteUp)) {
                    this.minusLoveCount(j)
                }
                if (i) {
                    GAG.Vote.unlike(j, function() {
                    }, function() {
                    });
                    this.addLoveCount(j);
                    this.handlers.unlikeHandler(j);
                    f.removeClass("green").removeClass("red")
                } else {
                    GAG.Vote.dislike(j, function() {
                    }, function() {
                    });
                    this.minusLoveCount(j);
                    this.handlers.dislikeHandler(j);
                    f.removeClass("green").addClass("red")
                }
            }
        },addLoveCount: function(g) {
            var e = this.getLoveCounter(g);
            var f = b("#jsid-entry-entity-" + g);
            var h = parseInt(f.data("entry-votes"));
            if (isNaN(h)) {
                return
            }
            h++;
            e.text(GAG.Utils.formatNumber(h));
            f.data("entry-votes", h);
            GAG.PostController.updateFastItem(g, "votes", h)
        },minusLoveCount: function(g) {
            var e = this.getLoveCounter(g);
            var f = b("#jsid-entry-entity-" + g);
            var h = parseInt(f.data("entry-votes"));
            if (isNaN(h)) {
                return
            }
            h--;
            e.text(GAG.Utils.formatNumber(h));
            f.data("entry-votes", h);
            GAG.PostController.updateFastItem(g, "votes", h)
        },updateFastItem: function(f, e, g) {
            if (GAG.PostController._fastItems != null) {
                if (GAG.PostController._fastItems[f] != "undefined") {
                    GAG.PostController._fastItems[f][e] = g
                }
            }
        },getLoveCounter: function(e) {
            return b("#love-count-" + e)
        },bindStickyEntryBars: function() {
            if (GAG.Page.isProfilePage()) {
                this._entryStickyElementMarginTop = this._entryStickyElementMarginTopProfile
            }
            b(a).on("scroll resize", null, null, b.proxy(this.handlers.entryStickElementHandler, this))
        },bindShowHideReportLinkEvents: function() {
            b(this.selectors.CONTAINER).on("mouseover", this.selectors.ENTRY_CONTAINER, null, b.proxy(this.handlers.entryMouseOverShowSecondaryLinkHandler, this));
            b(this.selectors.CONTAINER).on("mouseout", this.selectors.ENTRY_CONTAINER, null, b.proxy(this.handlers.entryMouseOutHideSecondaryLinkHandler, this))
        },bindVoteUpElements: function() {
            b(this.selectors.CONTAINER).on("click", this.selectors.ENTRY_UPVOTE_BUTTON, b.proxy(this.onVoteUp, this))
        },bindVoteDownElements: function() {
            b(this.selectors.CONTAINER).on("click", this.selectors.ENTRY_DOWNVOTE_BUTTON, b.proxy(this.onVoteDown, this))
        },bindCommentElements: function() {
            b(this.selectors.CONTAINER).on("click", this.selectors.ENTRY_COMMENT_BUTTON, b.proxy(function(l) {
                l.preventDefault();
                var j = b(l.currentTarget);
                var h = j.closest(this.selectors.ENTRY_CONTAINER);
                var f = j.closest(this.selectors.ENTRY_ENTITY);
                var m = h.find(this.selectors.ENTRY_TITLE).html();
                var i = f.data("entry-id");
                var n = b("#jsid-list-facebook-comment-plugin-" + i);
                if (f.hasClass("post-page")) {
                    this.scrollToComment();
                    return
                }
                if (!n.hasClass("post-comment")) {
                    n.addClass("post-comment");
                    var g = {className: "comment-spinner"};
                    GAG.PageController.loadSpinner("jsid-list-facebook-comment-plugin-" + i, g);
                    GAG.Facebook.renderComment("jsid-list-facebook-comment-plugin-" + i, function() {
                        b(".comment-spinner").hide()
                    }, {"data-href": f.data("entry-url"),"data-num-posts": 10,"data-width": 460})
                } else {
                    n.html("");
                    n.removeClass("post-comment")
                }
            }, this))
        },bindExpandElements: function() {
            b(this.selectors.CONTAINER).on("click", this.selectors.ENTRY_EXPAND_BTN, null, b.proxy(function(h) {
                h.preventDefault();
                var g = b(h.currentTarget);
                var f = g.closest(this.selectors.ENTRY_POST_CONTAINER);
                f.removeClass("long");
                g.addClass("hide")
            }, this))
        },bindSearchResultElements: function() {
            b(this.selectors.CONTAINER).on("click", this.selectors.SEARCH_ENTRY_ENTITY, null, b.proxy(function(h) {
                h.preventDefault();
                var f = b(h.currentTarget);
                var g = f.data("entry-url");
                a.open(g, "_blank")
            }, this))
        },bindEntryCoverElements: function() {
            b(this.selectors.CONTAINER).on("click", this.selectors.ENTRY_NSFW_COVER, null, b.proxy(function(g) {
                g.preventDefault();
                var f = b(g.currentTarget).parents(this.selectors.ENTRY_ENTITY).data("entry-url");
                GAG.AccountController.setSafeMode(0, f)
            }, this));
            b(this.selectors.CONTAINER).on("click", this.selectors.ENTRY_VIDEO_COVER, null, b.proxy(function(m) {
                m.preventDefault();
                var l = b(m.currentTarget);
                var h = l.closest(this.selectors.ENTRY_ENTITY);
                var g = b(m.currentTarget).parents(this.selectors.ENTRY_VIDEO_CONTAINER);
                var i = "500";
                var f = "277";
                if (h.hasClass("post-page")) {
                    var i = "600";
                    var f = "340"
                }
                var j = '<iframe width="' + i + '" height="' + f + '" src="http://www.youtube.com/embed/' + g.data("video-id") + '?autoplay=1&controls=1&iv_load_policy=3" frameborder="0" allowfullscreen></iframe>';
                g.html(j)
            }, this));
            b(this.selectors.CONTAINER).on("click", this.selectors.ENTRY_ANIMATED_COVER, null, b.proxy(function(j) {
                j.preventDefault();
                var i = b(j.currentTarget);
                var f = i.find(this.selectors.ENTRY_ANIMATED_CONTAINER_ANIMATED);
                var h = i.find(this.selectors.ENTRY_ANIMATED_CONTAINER_STATIC);
                f.toggleClass("hide");
                h.toggleClass("hide");
                if (f.hasClass("hide")) {
                    var g = f.find("img");
                    g.prop("src", g.prop("src"))
                }
            }, this))
        },bindReportElements: function() {
            b(this.selectors.CONTAINER).on("click", this.selectors.REPORT_LINK, null, b.proxy(this.handlers.reportHandler, this));
            b(this.selectors.MODAL_REPORT_SUBMIT).on("click", null, null, b.proxy(this.handlers.reportSubmitHandler, this))
        },bindShareElements: function() {
            b(this.selectors.CONTAINER).on("mouseenter mouseleave", "a.badge-item-share, .badge-item-share-menu", b.proxy(function(i) {
                i.preventDefault();
                var j = b(i.currentTarget);
                var f = j.closest(this.selectors.ENTRY_ENTITY);
                var g = f.data("entry-id");
                var h = b("#share-menu-" + g);
                if (!h.hasClass("rendered-like")) {
                    GAG.Facebook.renderLike("jsid-list-facebook-like-plugin-" + g, function() {
                    }, {"data-href": f.data("entry-url")});
                    h.addClass("rendered-like")
                }
                if (h.hasClass("hide")) {
                    b(this.selectors.ENTRY_SHARE_MENU).addClass("hide");
                    h.removeClass("hide")
                } else {
                    h.addClass("hide")
                }
            }, this))
        },bindShortcutKeys: function() {
            GAG.KeyboardController.bindAction("l", b.proxy(this.onVoteUp, this));
            GAG.KeyboardController.bindAction("h", b.proxy(this.onVoteDown, this))
        },bindZoomElements: function() {
            b(this.selectors.CONTAINER).on("click", this.selectors.ENTRY_POST_ZOOM, b.proxy(function(h) {
                h.preventDefault();
                var g = b(h.currentTarget);
                var f = g.closest(this.selectors.ENTRY_ENTITY);
                this.showPostZoomOverlay(f)
            }, this))
        },_bindEntryTrackingEvents: function() {
            GAG.Facebook.addInitCallback("all", b.proxy(function() {
                FB.Event.subscribe("edge.create", b.proxy(function(g, j, f) {
                    var i = b(j.dom);
                    var h = i.closest(this.selectors.ENTRY_ENTITY).data("entry-id");
                    var e = i.parents(GAG.ListController.selectors.LIST_VIEW).length > 0 ? "l" : "p";
                    GAG.Track.event("social", "fb.l", {platform: "d",entry: h,view: e})
                }, this));
                FB.Event.subscribe("edge.remove", b.proxy(function(g, j, f) {
                    var i = b(j.dom);
                    var h = i.closest(this.selectors.ENTRY_ENTITY).data("entry-id");
                    var e = i.parents(GAG.ListController.selectors.LIST_VIEW).length > 0 ? "l" : "p";
                    GAG.Track.event("social", "fb.rl", {platform: "d",entry: h,view: e})
                }, this));
                FB.Event.subscribe("comment.create", b.proxy(function(i) {
                    var f = i.href;
                    var h = b(this.selectors.ENTRY_ENTITY + '[data-entry-url="' + f + '"]');
                    var g = h.data("entry-id");
                    var e = h.parents(GAG.ListController.selectors.LIST_VIEW).length > 0 ? "l" : "p";
                    GAG.Track.event("social", "fb.c", {platform: "d",entry: g,view: e})
                }, this));
                FB.Event.subscribe("comment.remove", b.proxy(function(i) {
                    var f = i.href;
                    var h = b(this.selectors.ENTRY_ENTITY + '[data-entry-url="' + f + '"]');
                    var g = h.data("entry-id");
                    var e = h.parents(GAG.ListController.selectors.LIST_VIEW).length > 0 ? "l" : "p";
                    GAG.Track.event("social", "fb.rc", {platform: "d",entry: g,view: e})
                }, this))
            }, this))
        },replacePostUrl: function(f) {
            var e = "http://" + document.location.hostname + "/gag/" + f;
            if (typeof (a.history.pushState) != "undefined") {
                a.history.pushState({}, "", e)
            }
        },updatePostUrl: function(f) {
            var e = "http://" + document.location.hostname + "/gag/" + f;
            if (typeof (a.history.replaceState) != "undefined") {
                a.history.replaceState({}, "", e)
            }
        },recoverOrginialUrl: function() {
            a.history.go(-1)
        },showPostZoomOverlay: function(e) {
            var f = e.find("img").first().clone().removeAttr("class");
            b(this.selectors.MODAL_POST_ZOOM_CONTAINER).find(".badge-post-zoom-img").html("").append(f);
            GAG.OverlayController.showOverlay(this.selectors.MODAL_POST_ZOOM_CONTAINER)
        },hidePostZoomOverlay: function() {
            b(this.selectors.MODAL_POST_ZOOM_CONTAINER).addClass("hide");
            b("body").removeClass("no-scroll")
        },scrollToComment: function() {
            var e = b("#" + this.selectors.ENTRY_MAIN_POST_COMMENT_ID);
            b("html,body").animate({scrollTop: e.offset().top - 60}, 100)
        },upvoteEntry: function(e) {
            b(e).find(this.selectors.ENTRY_UPVOTE_BUTTON).first().click()
        },downvoteEntry: function(e) {
            b(e).find(this.selectors.ENTRY_DOWNVOTE_BUTTON).first().click()
        },commentEntry: function(e) {
            var f = b(e).first();
            if (f.hasClass("post-page")) {
                this.scrollToComment()
            } else {
                b(e).find(this.selectors.ENTRY_COMMENT_BUTTON).first().click()
            }
        },playEntry: function(e) {
            var g = b(e).first();
            var h = g.find(this.selectors.ENTRY_EXPAND_BTN);
            var f = g.find(this.selectors.ENTRY_VIDEO_COVER);
            var i = g.find(this.selectors.ENTRY_ANIMATED_COVER);
            if (h.length) {
                h.click()
            } else {
                if (f.length) {
                    f.click()
                } else {
                    if (i.length) {
                        i.click()
                    }
                }
            }
        },prevEntry: function() {
            b(".badge-prev-post-entry").click()
        },nextEntry: function() {
            b(".badge-next-post-entry").click()
        }});
    GAG.VoteController = b.extend({}, new GAG.Controller(), {VOTE_PAGE_URI: "/v",init: function() {
            if (!GAG.Page.isNewVotePage()) {
                return
            }
            this.Comment.init();
            this.bindElements()
        },Handlers: {loadNextEntry: function() {
                var f = GAG.Configs.get("data.next_id");
                if (!f) {
                    f = 0
                }
                var e = GAG.VoteController.VOTE_PAGE_URI;
                if (f) {
                    e += "/" + f
                }
                GAG.Page.load(e)
            },likeHandler: function(f, e) {
                b("#dislike-btn-" + f).removeClass("active");
                b("#like-btn-" + f).addClass("active");
                if (e) {
                    GAG.VoteController.Handlers.loadNextEntry()
                }
            },dislikeHandler: function(f, e) {
                b("#like-btn-" + f).removeClass("active");
                b("#dislike-btn-" + f).addClass("active");
                if (e) {
                    GAG.VoteController.Handlers.loadNextEntry()
                }
            },unlikeHandler: function(f, e) {
                b("#like-btn-" + f).removeClass("active");
                b("#dislike-btn-" + f).removeClass("active");
                if (e) {
                    GAG.VoteController.Handlers.loadNextEntry()
                }
            }},bindVoteActions: function() {
            b(".badge-vote-like").on("click", function(j) {
                j.preventDefault();
                var g = b(this);
                var f = g.attr("data-entry-id");
                var i = g.hasClass("active");
                var h = GAG.Utils.formatPostLink(f);
                if (i) {
                    GAG.GA.track("Unlike", "NewVoteClicked", h);
                    GAG.Vote.unlike(f, GAG.VoteController.Handlers.unlikeHandler, GAG.VoteController.Handlers.likeHandler)
                } else {
                    GAG.GA.track("Like", "NewVoteClicked", h);
                    GAG.Vote.like(f, GAG.VoteController.Handlers.likeHandler, GAG.VoteController.Handlers.unlikeHandler)
                }
            });
            b(".badge-vote-dislike").on("click", function(j) {
                j.preventDefault();
                var g = b(this);
                var f = g.attr("data-entry-id");
                var i = g.hasClass("active");
                var h = GAG.Utils.formatPostLink(f);
                if (i) {
                    GAG.GA.track("Unlike", "NewVoteClicked", h);
                    GAG.Vote.unlike(f, GAG.VoteController.Handlers.unlikeHandler, GAG.VoteController.Handlers.likeHandler)
                } else {
                    GAG.GA.track("Dislike", "NewVoteClicked", h);
                    GAG.Vote.dislike(f, GAG.VoteController.Handlers.dislikeHandler, GAG.VoteController.Handlers.unlikeHandler)
                }
            });
            b(".badge-vote-jump-next").on("click", function(f) {
                f.preventDefault();
                GAG.VoteController.Handlers.loadNextEntry()
            })
        },_timer: null,_keyboardDismissTime: 10000,_firstVisitCookieKey: "vote_first_visit",initKeyboardWizard: function() {
            var e = b.cookie(this._firstVisitCookieKey) == "1";
            if (e) {
                return
            }
            this.showKeyboardOverlay(true);
            this._timer = setTimeout("GAG.VoteController.showKeyboardOverlay(false);", this._keyboardDismissTime);
            b.cookie(this._firstVisitCookieKey, "1", GAG.Page.getCookieOptions())
        },showKeyboardOverlay: function(e) {
            var f = b(".badge-vote-keyboard");
            if (e) {
                f.animate({opacity: 1}, 200)
            } else {
                f.animate({opacity: 0}, 200)
            }
        },bindKeyboardOverlay: function() {
            var e = ".badge-vote-keyboard";
            b(e).on("mouseenter", function(f) {
                GAG.VoteController.showKeyboardOverlay(true)
            });
            b(e).on("mouseleave", function(f) {
                GAG.VoteController.showKeyboardOverlay(false)
            });
            this.initKeyboardWizard()
        },bindMenu: function() {
            var e = "#options-dropdown-menu";
            b(e).on("mouseleave", function(f) {
                b(this).addClass("hide")
            })
        },bindSharePopupMenu: function() {
            var e = ".badge-share-popup-menu, #share-bar-dropdown-menu";
            var g = "shifted-hide";
            function f(h) {
                var i = b("#share-bar-dropdown-menu");
                if (h) {
                    i.removeClass(g).css("top", "")
                } else {
                    i.addClass(g).css("top", "-150px")
                }
            }
            b(".badge-share-popup-menu").on("click", function(j) {
                j.preventDefault();
                var i = b("#share-bar-dropdown-menu");
                var h = i.hasClass(g);
                f(h)
            });
            b("#share-bar-dropdown-menu").on("mouseleave", function(h) {
                h.preventDefault();
                f(false)
            });
            b(".badge-highlight-text").on("click", function(h) {
                b(this).select()
            })
        },_defaultShareCookieKey: "default_share_platform",bindDefaultShareButton: function() {
            b("a.badge-default-share").on("click", function(h) {
                var g = b(this);
                var f = g.attr("data-platform");
                b.cookie(GAG.VoteController._defaultShareCookieKey, f, GAG.Page.getCookieOptions());
                GAG.VoteController.updateShareButton(f)
            })
        },updateShareButton: function(e) {
            var g = b("#default-share-button");
            var h = g.attr("data-platform");
            var f = b("#share-button-" + e);
            if (h == e) {
                return
            }
            g.attr("onclick", f.attr("onclick"));
            g.removeClass(h).addClass(e).attr("data-platform", e)
        },bindCommentToggler: function() {
            b(".badge-vote-comments-toggle").on("click", function(f) {
                f.preventDefault();
                b("#sidebar-comment").toggle()
            })
        },bindQuickReport: function() {
            b("a.badge-quick-post-report").click(function(m) {
                m.preventDefault();
                var i = b(this);
                var l = function(n, e) {
                    i.text("Reporting...");
                    if (e) {
                        i.addClass("reported");
                        i.text("Reported");
                        GAG.VoteController.Handlers.loadNextEntry()
                    }
                };
                var g = function(n, e) {
                    i.text("Report");
                    if (e) {
                        GAG.VoteController.Handlers.loadNextEntry()
                    }
                };
                var h = i.hasClass("reported");
                if (h) {
                    return
                }
                var j = b(this).attr("data-entry-id");
                var f = 2;
                GAG.Entry.report(j, f, l, g)
            })
        },bindElements: function() {
            this.bindVoteActions();
            this.bindSharePopupMenu();
            this.bindQuickReport();
            this.bindCommentToggler();
            this.bindDefaultShareButton();
            this.bindKeyboardOverlay();
            this.bindMenu()
        },onResize: function() {
            if (!GAG.Page.isNewVotePage()) {
                return
            }
            this.Comment.fitElements()
        },onDocumentClicked: function() {
        },Comment: {_ns: "window.GAG.VoteController.Comment",_checker: false,_checkInterval: 1000,_commentBoxHeight: 0,_fbInited: false,ids: {COMMENT_BOX_SLIDER_WRAPPER: "sidebar-comment",COMMENT_BOX_ELEMENT: "facebook-comment"},init: function() {
                this.renderCommentBox()
            },getNamespace: function() {
                return this._ns
            },getSliderWrapper: function() {
                return b("#" + this.ids.COMMENT_BOX_SLIDER_WRAPPER)
            },getCommentBox: function() {
                return b("#" + this.ids.COMMENT_BOX_ELEMENT)
            },renderCommentBox: function() {
                GAG.Facebook.renderElement(this.ids.COMMENT_BOX_ELEMENT, b.proxy(this.fitElements, this))
            },monitorCommentBox: function() {
                if (!this._checker) {
                    this._checker = setInterval(this.getNamespace() + ".commentBoxSizeCheck();", this._checkInterval)
                }
            },commentBoxSizeCheck: function() {
            },fitElements: function() {
                var h = b(a).height();
                var e = 92;
                var f = 291;
                commentBoxHeight = h - e - f;
                var g = 50;
                containerHeight = h - g;
                b("#facebook-comment").height(commentBoxHeight);
                b("div#overlay .container").height(containerHeight)
            }}});
    GAG.PageController = b.extend({}, new GAG.Controller(), {init: function() {
            this.bindElements();
            GAG.Track.page()
        },getUniqueDomId: function(e) {
            var f;
            while (!f || document.getElementById(f)) {
                f = (e ? e : "jsid_dom") + "_" + parseInt((Math.random() * 999999), 10)
            }
            return f
        },_toastFadeDuration: 500,_showFooterNavAfter: 600,_sidebarStickyElementMarginTop: 20,_sidebarStickyHeight: 0,_topVolatileElementHeight: 0,_topStickyElementHeight: 0,_autoCompleteMinLength: 2,_autoCompleteMaxResult: 10,_isNotificationShown: false,_lastNotificationUpdateTs: false,_isUpdatingNotification: false,_isMarkingNotificationAsRead: false,_themeIdCookieKey: "themeId",selectors: {THEME_FILES: ".badge-theme-file",FOOTER_NAV: ".footer .buttons-area",PREV_ENTRY: "a.badge-prev-entry",NEXT_ENTRY: "a.badge-next-entry",SCROLL_TO_TOP: "a.badge-scroll-to-top",HEADER_TOP_NAV: ".badge-sticky-nav",HEADER_TOP_BANNER: ".badge-volatile-banner",HEADER_USER_MENU: "#jsid-header-user-menu",HEADER_USER_ITEM: "#jsid-header-user-menu-items",HEADER_FUNNY_MENU: "#jsid-header-funny-menu",HEADER_FUNNY_ITEM: "#jsid-header-funny-menu-items",HEADER_NOTIFICATION_MENU: "#jsid-header-notification-menu",HEADER_NOTIFICATION_ITEM: "#jsid-header-notification-items",HEADER_NOTIFICATION_CONTAINER: "#jsid-header-notification-items-container",HEADER_NOTIFICATION_SEE_ALL: "#jsid-header-notification-see-all",HEADER_UPLOAD_ITEM: ".badge-upload-items",HEADER_UPLOAD_MENU: "#jsid-upload-menu",HEADER_DOWNLOAD_MENU: "#jsid-header-download-menu",HEADER_DOWNLOAD_ITEM: "#jsid-header-download-menu-items",HEADER_SEARCH: ".badge-header-search",HEADER_SEARCH_INPUT: "#jsid-search-input",HEADER_TOAST: ".badge-toast-container",HEADER_TOAST_MESSAGE: ".badge-toast-message",HEADER_TOAST_CLOSE: ".badge-toast-close",SIDEBAR_STICKY: ".badge-sticky-sidedock-sticky",SIDEBAR_STICKY_STATIC: ".badge-sticky-sidedock-static",POST_PAGE_STICKY: ".badge-sticky-post-page-sticky",POST_PAGE_STICKY_STATIC: ".badge-sticky-post-page-static",SUBNAV_STICKY: ".badge-sticky-subnav-sticky",SUBNAV_STICKY_STATIC: ".badge-sticky-subnav-static",CONTAINTER: "#container",PAGE: ".badge-page",CLICK_EVENT_SELECTOR: ".badge-evt, .badge-track",CLICK_EVENT_NOFOLLOW_SELECTOR: ".badge-track-no-follow"},onScroll: function() {
            this.checkFooterNavElements()
        },bindElements: function() {
            this.calculateHeights();
            this.bindStickyNav();
            this.bindStickySidebar();
            this.bindStickyPostPageBar();
            this.bindStickySubNav();
            this.bindFooterNavElements();
            this.bindCustomizeElements();
            this.bindUploadElements();
            this.bindUserSettingElements();
            this.bindGroupElements();
            this.bindDownloadElements();
            this.bindNotificationElements();
            this.bindSearchElements();
            this.bindToastElements();
            this.bindEventTracking();
            this.bindThemeElements();
            this.bindCloseAdvice();
            this.bindContactElements();
            this.bindEditorDashboardElements();
            this.bindPopupMenu()
        },calculateHeights: function() {
            this._topStickyElementHeight = b(this.selectors.HEADER_TOP_NAV).height();
            b(this.selectors.HEADER_TOP_BANNER).each(function() {
                GAG.PageController._topVolatileElementHeight += b(this).height()
            })
        },bindEditorDashboardElements: function() {
            b(".badge-period-dropdown-control .period").on("click", function() {
                event.preventDefault();
                b(this).next(".period-dropdown").toggleClass("hide")
            });
            b("#jsid-period-dropdown-from").datepicker({minDate: "-30D",maxDate: "+0D",changeMonth: true,numberOfMonths: 2,onClose: function(e) {
                    b("#jsid-period-dropdown-to").datepicker("option", "minDate", e)
                }});
            b("#jsid-period-dropdown-to").datepicker({minDate: "-30D",maxDate: "+0D",changeMonth: true,numberOfMonths: 2,onClose: function(e) {
                    b("#jsid-period-dropdown-from").datepicker("option", "maxDate", e)
                }});
            b("#jsid-period-dropdown-from, #jsid-period-dropdown-to, #ui-datepicker-div").click(function(e) {
                e.stopPropagation()
            });
            b(".badge-load-more-entry").on("click", function(h) {
                h.preventDefault();
                var g = b(this);
                g.data("original-text", g.text());
                g.text(g.data("loading-text"));
                var f = g.prop("href");
                if (typeof f != "undefined" && f != "") {
                    b.ajax({url: f,dataType: "json",success: function(l) {
                            var e = "";
                            for (var j = 0; j < l.ids.length; j++) {
                                var m = l.ids[j];
                                e += l.items[m]
                            }
                            b(".badge-posts-items").append(e);
                            if (l.loadMoreUrl != "") {
                                g.prop("href", l.loadMoreUrl);
                                g.text(g.data("original-text"));
                                g.data("original-text", "");
                                g.data("original-url", l.loadMoreUrl)
                            } else {
                                g.removeAttr("href");
                                g.text("No more posts")
                            }
                        }})
                }
            });
            b(".badge-second-col").on("change", function() {
                if (b(this).val() == "r") {
                    b(".badge-comment-col").addClass("hide");
                    b(".badge-report-col").removeClass("hide")
                } else {
                    if (b(this).val() == "c") {
                        b(".badge-comment-col").removeClass("hide");
                        b(".badge-report-col").addClass("hide")
                    }
                }
                b(".badge-update-url").each(function() {
                    var e = b(".badge-second-col").val();
                    var g = "&scol=";
                    if (e == "r") {
                        g += "r"
                    } else {
                        if (e == "c") {
                            g += "c"
                        }
                    }
                    var f = b(this).data("original-url") + g;
                    b(this).attr("href", f)
                })
            })
        },bindContactElements: function() {
            b("#jsid-contact-form").on("submit", b.proxy(function() {
                if (!b("#jsid-interaction-name").val().length) {
                    b("#jsid-contact-name-error").removeClass("hide");
                    return false
                } else {
                    b("#jsid-contact-name-error").addClass("hide")
                }
                if (!GAG.Validator.isValidEmail(b("#jsid-interaction-email").val())) {
                    b("#jsid-contact-email-error").removeClass("hide");
                    return false
                } else {
                    b("#jsid-contact-email-error").addClass("hide")
                }
                if (b("#jsid-email-category").val() == 0) {
                    b("#jsid-contact-category-error").removeClass("hide");
                    return false
                } else {
                    b("#jsid-contact-category-error").addClass("hide")
                }
                if (!b("#jsid-email-subject").val().length) {
                    b("#jsid-contact-subject-error").removeClass("hide");
                    return false
                } else {
                    b("#jsid-contact-subject-error").addClass("hide")
                }
                if (!b("#jsid-email-message").val().length) {
                    b("#jsid-contact-message-error").removeClass("hide");
                    return false
                } else {
                    b("#jsid-contact-message-error").addClass("hide")
                }
                var i = true;
                try {
                    if (Recaptcha) {
                        var g = Recaptcha.get_challenge();
                        var f = Recaptcha.get_response();
                        b("#recaptcha_challenge").val(g);
                        b("#recaptcha_response").val(f)
                    }
                } catch (h) {
                }
                if (!i) {
                    event.preventDefault();
                    return false
                }
                return true
            }, this))
        },bindSearchElements: function() {
            var g = b(this.selectors.HEADER_SEARCH);
            var e = b(this.selectors.HEADER_SEARCH_INPUT);
            var h = e.attr("id");
            b("body").on("mousedown", function(i) {
                if (e.length && i.target.id !== h && g.hasClass("selected") && !e.val().length) {
                    g.removeClass("selected");
                    e.removeAttr("placeholder")
                }
            });
            g.click(function() {
                if (!g.hasClass("selected")) {
                    g.addClass("selected");
                    e.attr("placeholder", e.data("placeholder")).focus();
                    return false
                }
            });
            if (e.length) {
                var f = {url: "/tags/suggest",appendTo: this.selectors.HEADER_SEARCH,menuClass: "search-suggestion small"};
                this.loadAutoComplete(this.selectors.HEADER_SEARCH_INPUT, f)
            }
        },loadAutoComplete: function(e, f) {
            var g = {url: (typeof f.url === "undefined") ? "" : f.url,appendTo: (typeof f.appendTo === "undefined") ? "" : f.appendTo,minLength: (typeof f.minLength === "undefined") ? this._autoCompleteMinLength : f.minLength,maxResult: (typeof f.maxResult === "undefined") ? this._autoCompleteMaxResult : f.maxResult,menuClass: (typeof f.menuClass === "undefined") ? "" : f.menuClass};
            b(e).autocomplete({source: function(i, h) {
                    b.ajax({url: g.url,dataType: "json",data: {tag: i.term},success: function(m) {
                            var j = m.slice(0, g.maxResult);
                            var l = "<strong>" + i.term + "</strong>";
                            h(b.map(j, function(n) {
                                return {label: l + n.substr(i.term.length),value: n}
                            }));
                            b(".ui-helper-hidden-accessible").addClass("hide")
                        }})
                },minLength: g.minLength,appendTo: g.appendTo,open: function() {
                    var h = b(".ui-autocomplete");
                    h.removeAttr("class").addClass(g.menuClass).removeAttr("style");
                    b(".ui-helper-hidden-accessible").addClass("hide")
                },select: function(i) {
                    var h = b(i.currentTarget);
                    b(GAG.PageController.selectors.HEADER_SEARCH_INPUT).val(h.find(".ui-state-focus").first().text());
                    h.closest("form").submit()
                }}).data("ui-autocomplete")._renderItem = function(h, i) {
                return b("<li></li>").data("ui-autocomplete-item", i).append("<a>" + i.label + "</a>").appendTo(h)
            }
        },toggleMenu: function(e) {
            return !(b(e).toggleClass("hide").hasClass("hide"))
        },showMenu: function(e) {
            b(e).removeClass("hide")
        },hideMenu: function(e) {
            b(e).addClass("hide")
        },loadSpinner: function(e, f) {
            var g = {lines: (typeof f.lines === "undefined") ? 10 : f.lines,length: (typeof f.length === "undefined") ? 8 : f.length,width: (typeof f.width === "undefined") ? 4 : f.width,radius: (typeof f.radius === "undefined") ? 10 : f.radius,corners: (typeof f.corners === "undefined") ? 1 : f.corners,rotate: (typeof f.rotate === "undefined") ? 0 : f.rotate,color: (typeof f.color === "undefined") ? "#555" : f.color,speed: (typeof f.speed === "undefined") ? 1 : f.speed,trail: (typeof f.trail === "undefined") ? 60 : f.trail,shadow: (typeof f.shadow === "undefined") ? false : f.shadow,hwaccel: (typeof f.hwaccel === "undefined") ? false : f.hwaccel,className: (typeof f.className === "undefined") ? "spinner" : f.className,zIndex: (typeof f.zIndex === "undefined") ? 2000000000 : f.zIndex,top: (typeof f.top === "undefined") ? "auto" : f.top,left: (typeof f.left === "undefined") ? "auto" : f.left};
            var h = document.getElementById(e);
            var i = new Spinner(g).spin(h)
        },updateLanguage: function(g) {
            var e = GAG.Page.getBackUrl();
            var f = "http://" + GAG.Page.getDomain() + "/profile/setlanguage/lang/" + g + "?url=" + e;
            a.location.href = f
        },bindStickySidebar: function() {
            if (b(this.selectors.SIDEBAR_STICKY_STATIC).length > 0) {
                b(a).scroll(b.proxy(function() {
                    var j = b(this.selectors.SIDEBAR_STICKY_STATIC).offset().top;
                    var i = b(this.selectors.SIDEBAR_STICKY);
                    var e = b(this.selectors.PAGE);
                    var h = b(".badge-block-ad");
                    this._sidebarStickyHeight = this._sidebarStickyHeight || b(this.selectors.SIDEBAR_STICKY_STATIC).height();
                    if (this.getWindowEffectiveScrollTop() <= j - this._sidebarStickyElementMarginTop) {
                        i.css("top", 0);
                        i.css("position", "relative")
                    } else {
                        if (this.getWindowEffectiveScrollTop() > j - this._sidebarStickyElementMarginTop && this.getWindowEffectiveScrollTop() < e.offset().top + e.height() - this._sidebarStickyHeight - this._sidebarStickyElementMarginTop) {
                            var g = this._topStickyElementHeight;
                            var f = b(a).scrollTop();
                            if (f < 0) {
                                f = 0
                            }
                            if (f < this._topVolatileElementHeight) {
                                g = g + this._topVolatileElementHeight - f
                            }
                            i.css("top", g);
                            i.css("position", "fixed")
                        } else {
                            var g = e.height() - this._sidebarStickyHeight - this._sidebarStickyElementMarginTop;
                            if (h.height() != null) {
                                g = g - h.height() - parseInt(h.css("margin-bottom"))
                            }
                            i.css("top", g);
                            i.css("position", "relative")
                        }
                    }
                }, this))
            }
        },bindStickyPostPageBar: function() {
            if (b(this.selectors.POST_PAGE_STICKY_STATIC).length > 0) {
                b(a).scroll(b.proxy(function() {
                    var e = this._topVolatileElementHeight;
                    if (b(a).scrollTop() <= e) {
                        b(this.selectors.POST_PAGE_STICKY).css("top", 0);
                        b(this.selectors.POST_PAGE_STICKY).css("position", "absolute")
                    } else {
                        b(this.selectors.POST_PAGE_STICKY).css("top", 0);
                        b(this.selectors.POST_PAGE_STICKY).css("position", "fixed")
                    }
                }, this))
            }
        },bindStickyNav: function() {
            b(a).scroll(b.proxy(function() {
                var e = b(this.selectors.HEADER_TOP_NAV);
                b(this.selectors.SUBNAV_STICKY_STATIC).height(e.height() + 1);
                if (b(a).scrollTop() > this._topVolatileElementHeight) {
                    e.css("top", 0);
                    e.css("position", "fixed");
                    e.css("z-index", 3)
                } else {
                    e.removeAttr("style")
                }
            }, this))
        },bindStickySubNav: function() {
            if (b(this.selectors.SUBNAV_STICKY_STATIC).length > 0) {
                b(a).scroll(b.proxy(function() {
                    var e = b(this.selectors.SUBNAV_STICKY_STATIC).position().top;
                    b(this.selectors.SUBNAV_STICKY_STATIC).height(b(this.selectors.SUBNAV_STICKY).height());
                    if (b(a).scrollTop() <= e) {
                        b(this.selectors.SUBNAV_STICKY).css("top", 0);
                        b(this.selectors.SUBNAV_STICKY).css("position", "relative")
                    } else {
                        b(this.selectors.SUBNAV_STICKY).css("top", 0);
                        b(this.selectors.SUBNAV_STICKY).css("position", "fixed")
                    }
                }, this))
            }
        },bindUserSettingElements: function() {
            b(this.selectors.HEADER_USER_MENU + ", " + this.selectors.HEADER_USER_ITEM).click(b.proxy(function(g) {
                g.stopPropagation();
                var f = this.toggleMenu(this.selectors.HEADER_USER_ITEM);
                this.hidePopupMenu(f ? this.selectors.HEADER_USER_ITEM : null)
            }, this))
        },hidePopupMenu: function(f) {
            var h = [this.selectors.HEADER_FUNNY_ITEM, this.selectors.HEADER_DOWNLOAD_ITEM, this.selectors.HEADER_USER_ITEM, this.selectors.HEADER_NOTIFICATION_ITEM, this.selectors.HEADER_UPLOAD_ITEM];
            var g = {};
            g[this.selectors.HEADER_FUNNY_ITEM] = this.selectors.HEADER_FUNNY_MENU;
            g[this.selectors.HEADER_DOWNLOAD_ITEM] = this.selectors.HEADER_DOWNLOAD_MENU;
            g[this.selectors.HEADER_USER_ITEM] = this.selectors.HEADER_USER_MENU;
            g[this.selectors.HEADER_NOTIFICATION_ITEM] = this.selectors.HEADER_NOTIFICATION_MENU;
            g[this.selectors.HEADER_UPLOAD_ITEM] = this.selectors.HEADER_UPLOAD_MENU;
            if (f != this.selectors.HEADER_NOTIFICATION_ITEM) {
                GAG.PageController._isNotificationShown = false
            }
            h = b.grep(h, function(l) {
                return l != f
            });
            b(h.join(",")).addClass("hide");
            for (var j in g) {
                var e = g[j];
                var i = "";
                switch (j) {
                    case this.selectors.HEADER_FUNNY_ITEM:
                        i = "selected-alt";
                        break;
                    case this.selectors.HEADER_USER_ITEM:
                        i = "selected";
                        e = e + " a";
                        break;
                    case this.selectors.HEADER_DOWNLOAD_ITEM:
                        i = "selected";
                        break;
                    case this.selectors.HEADER_NOTIFICATION_ITEM:
                        i = "selected";
                        e = e + " a";
                        break
                }
                if (j != f) {
                    b(e).removeClass("selected-alt").removeClass("selected")
                } else {
                    b(e).addClass(i)
                }
            }
        },bindPopupMenu: function() {
            b("body").on("click", b.proxy(function(f) {
                this.hidePopupMenu()
            }, this))
        },bindGroupElements: function() {
            b(this.selectors.HEADER_FUNNY_MENU + ", " + this.selectors.HEADER_FUNNY_ITEM).click(b.proxy(function(g) {
                g.stopPropagation();
                var f = this.toggleMenu(this.selectors.HEADER_FUNNY_ITEM, this.selectors.HEADER_FUNNY_MENU);
                this.hidePopupMenu(f ? this.selectors.HEADER_FUNNY_ITEM : null)
            }, this))
        },bindDownloadElements: function() {
            b(this.selectors.HEADER_DOWNLOAD_MENU + ", " + this.selectors.HEADER_DOWNLOAD_ITEM).click(b.proxy(function(g) {
                g.stopPropagation();
                var f = this.toggleMenu(this.selectors.HEADER_DOWNLOAD_ITEM);
                this.hidePopupMenu(f ? this.selectors.HEADER_DOWNLOAD_ITEM : null)
            }, this))
        },bindNotificationElements: function() {
            if (!GAG.Configs.get("user.id")) {
                return
            }
            b(this.selectors.HEADER_NOTIFICATION_ITEM).on("click", this.selectors.CLICK_EVENT_SELECTOR, b.proxy(this._handelClickEventTracking, this));
            b(this.selectors.HEADER_NOTIFICATION_ITEM).tinyscrollbar({invertscroll: true});
            GAG.PageController.getNotifications();
            b(document).click(b.proxy(function(f) {
                if (GAG.PageController._isNotificationShown) {
                    GAG.PageController._isNotificationShown = !GAG.PageController._isNotificationShown;
                    this.hideMenu(this.selectors.HEADER_NOTIFICATION_ITEM);
                    b(this.selectors.HEADER_NOTIFICATION_MENU).removeClass("menu");
                    b(this.selectors.HEADER_NOTIFICATION_MENU + " a").removeClass("selected")
                }
            }, this));
            b(this.selectors.HEADER_NOTIFICATION_MENU).click(b.proxy(function(f) {
                f.stopPropagation();
                f.preventDefault();
                if (GAG.PageController._isNotificationShown) {
                    this.hideMenu(this.selectors.HEADER_NOTIFICATION_ITEM);
                    b(this.selectors.HEADER_NOTIFICATION_MENU).removeClass("menu");
                    b(this.selectors.HEADER_NOTIFICATION_MENU + " a").removeClass("selected");
                    this._handelClickEventTracking(f)
                } else {
                    this.showMenu(this.selectors.HEADER_NOTIFICATION_ITEM);
                    b(this.selectors.HEADER_NOTIFICATION_MENU).addClass("menu");
                    b(this.selectors.HEADER_NOTIFICATION_MENU + " a").addClass("selected");
                    b(this.selectors.HEADER_NOTIFICATION_ITEM).tinyscrollbar_update({invertscroll: true});
                    GAG.PageController.markNotificationsAsRead();
                    this._handelClickEventTracking(f);
                    this.hidePopupMenu(this.selectors.HEADER_NOTIFICATION_ITEM)
                }
                GAG.PageController._isNotificationShown = !GAG.PageController._isNotificationShown
            }, this))
        },bindUploadElements: function() {
            b(this.selectors.HEADER_UPLOAD_MENU).click(b.proxy(function(f) {
                f.stopPropagation();
                this.toggleMenu(this.selectors.HEADER_UPLOAD_ITEM);
                this.hidePopupMenu(this.selectors.HEADER_UPLOAD_ITEM)
            }, this));
            b(".badge-upload-url").on("click", function(f) {
                f.preventDefault();
                b("#jsid-upload-url-btn").trigger("click")
            });
            b(".badge-upload-image").on("click", function(f) {
                f.preventDefault();
                b("#jsid-upload-file-btn").trigger("click")
            });
            b(".badge-upload-selector").on("click", function(f) {
                f.preventDefault();
                b(GAG.UploadController.selectors.UPLOAD_TITLE_INPUT).val("");
                b("#jsid-source-input").addClass("hide").val("");
                b("#upload-file input[type=checkbox]").removeAttr("checked");
                b("#upload-file p.error-message").text("");
                GAG.OverlayController.showOverlay("#modal-upload")
            })
        },bindCustomizeElements: function() {
            b(".badge-personalise-btn").on("click", function(f) {
                f.preventDefault();
                b(this).toggleClass("selected");
                b("#jsid-personalise-selector").slideToggle("fast", function() {
                })
            });
            b(".badge-personalise-sections, .badge-personalise-options").on("click", function(g) {
                g.preventDefault();
                b(this).toggleClass("on");
                var f = b(this).find("input");
                if (f.val() == "1") {
                    f.val("")
                } else {
                    f.val("1")
                }
            });
            b(".badge-personalise-option-nsfw").on("click", function(h) {
                h.preventDefault();
                var g = (b(this).find("input").val() == "1") ? 0 : 1;
                if (!GAG.User.isLoggedIn()) {
                    var f = GAG.Page.getCookieOptions();
                    f.domain = "." + document.domain;
                    b.cookie("side_personalize", 1, f);
                    GAG.AccountController.setSafeMode(g, a.location.href)
                }
            });
            b("#jsid-personalise-btn-save").on("click", function(f) {
                f.preventDefault();
                b("#jsid-personalise-selector").slideUp("fast", function() {
                    b("#jsid-personalise-form").submit()
                })
            });
            b("#jsid-personalise-btn-reset").on("click", function(f) {
                f.preventDefault();
                var g = "This will remove all your manual personalisation settings.";
                if (confirm(g)) {
                    b("#jsid-personalise-form input[name=customize_reset]").val("1");
                    b("#jsid-personalise-selector").slideUp("fast", function() {
                        b("#jsid-personalise-form").submit()
                    })
                }
            })
        },resetCustomize: function() {
            b("#form-modal-customize").find("input:checkbox").each(function() {
                var e = b(this);
                if (e.data("checked")) {
                    e.attr("checked", "checked")
                } else {
                    e.removeAttr("checked")
                }
            })
        },bindFooterNavElements: function() {
            var g = b(this.selectors.SCROLL_TO_TOP);
            g.on("click", function(h) {
                h.preventDefault();
                GAG.KeyboardController.scrollToTop()
            });
            var f = b(this.selectors.PREV_ENTRY);
            f.on("click", function(h) {
                h.preventDefault();
                GAG.ListController.scrollToPrevEntry()
            });
            var e = b(this.selectors.NEXT_ENTRY);
            e.on("click", function(h) {
                h.preventDefault();
                GAG.ListController.scrollToNextEntry()
            })
        },checkFooterNavElements: function() {
            if (b(a).scrollTop() > this._showFooterNavAfter) {
                b(this.selectors.FOOTER_NAV).show()
            } else {
                b(this.selectors.FOOTER_NAV).hide()
            }
        },bindToastElements: function() {
            b(this.selectors.HEADER_TOAST_CLOSE).click(b.proxy(function(e) {
                e.preventDefault();
                this.hideToast()
            }, this));
            if (b(this.selectors.HEADER_TOAST).is(":visible")) {
                setTimeout(b.proxy(function() {
                    this.hideToast()
                }, this), 5000)
            }
        },bindCloseAdvice: function() {
            b(".badge-advice-close").click(b.proxy(function(e) {
                e.preventDefault();
                var f = b(e.currentTarget);
                b(".badge-announcement-banner").addClass("hide");
                b(".badge-advice").removeClass("before");
                b.cookie("announcement_banner", 0, GAG.Page.getCookieOptions())
            }, this))
        },_trackGaEvent: function(g) {
            var i = g.attr("data-evt");
            if (!i) {
                return
            }
            i += "";
            var f = i.split(",");
            var h = "", l = "", e = "", j = 1;
            h = f.shift();
            l = f.shift();
            e = f.shift();
            GAG.GA.track(h, l, e, j)
        },_trackEvent: function(e) {
            var o = e.attr("data-track");
            if (!o || o == undefined) {
                return
            }
            o += "";
            var p = o.split(",");
            var h = p.shift();
            var n = p.shift();
            var l = p.shift();
            var i = p.shift();
            var f = p.shift();
            var m = p.shift();
            var j = p.shift();
            var g = {label: l,labelValue: i,platform: f,entry: m,view: j};
            GAG.Track.event(h, n, g)
        },_handelClickEventTracking: function(i) {
            var g = b(i.currentTarget);
            this._trackGaEvent(g);
            this._trackEvent(g);
            var f = g.prop("tagName");
            var e = g.attr("href") + "";
            var h = g.attr("target");
            var l = g.is(this.selectors.CLICK_EVENT_NOFOLLOW_SELECTOR);
            if (!l && f == "A" && (e.indexOf("http") === 0 || e.indexOf("/") === 0) && !h) {
                if (i) {
                    i.preventDefault()
                }
                var j = "window.location.href = '" + e + "';";
                a.setTimeout(j, 100)
            }
        },bindEventTracking: function() {
            b(this.selectors.CONTAINTER).on("click", this.selectors.CLICK_EVENT_SELECTOR, b.proxy(this._handelClickEventTracking, this))
        },bindThemeElements: function() {
            b(".badge-theme-selector").on("click", b.proxy(function(i) {
                var h = b(i.currentTarget);
                var f = h.find("#jsid-theme-id").text().toLowerCase();
                var g = "white";
                if (f == "white") {
                    g = "grey"
                } else {
                    g = "white"
                }
                this.switchToTheme(g);
                h.find("#jsid-theme-id").text(g);
                b.cookie(this._themeIdCookieKey, g, GAG.Page.getCookieOptions())
            }, this))
        },_cleanToastColor: function(e) {
            e = b(e);
            var g = e.attr("class").split(/\s+/);
            for (var f = 0; f < g.length; f++) {
                if (g[f].substr(0, 12) == "toast-color-") {
                    e.removeClass(g[f])
                }
            }
        },getWindowEffectiveScrollTop: function() {
            if (b(a).scrollTop() < this._topVolatileElementHeight) {
                return this._topVolatileElementHeight + this._topStickyElementHeight
            }
            return b(a).scrollTop() + this._topStickyElementHeight
        },scrollToTop: function() {
            b("html, body").animate({scrollTop: 0}, 300)
        },ensureLoggedIn: function(e) {
            if (GAG.User.isLoggedIn()) {
                return true
            } else {
                GAG.AccountController.presentSignupForm(e);
                return false
            }
        },showToast: function(g, f, h) {
            var e = b(this.selectors.HEADER_TOAST);
            e.hide();
            this._cleanToastColor(e);
            b(this.selectors.HEADER_TOAST).addClass("toast-color-" + f);
            b(this.selectors.HEADER_TOAST_MESSAGE).text(g);
            b(this.selectors.HEADER_TOAST).fadeIn(this._toastFadeDuration);
            if (typeof h != "undefined") {
                setTimeout(b.proxy(function() {
                    this.hideToast()
                }, this), h)
            }
        },hideToast: function() {
            b(this.selectors.HEADER_TOAST).fadeOut(this._toastFadeDuration)
        },switchToTheme: function(e) {
            b(this.selectors.THEME_FILES).attr("media", "none");
            b(this.selectors.THEME_FILES + "[data-theme-id=" + e + "]").attr("media", "screen,projection")
        },getNotifications: function() {
            if (GAG.PageController._isUpdatingNotification) {
                return
            }
            GAG.PageController._isUpdatingNotification = true;
            var e = b.ajax({url: "/notifications.json",dataType: "json",success: function(f) {
                    GAG.PageController._isUpdatingNotification = false;
                    GAG.PageController._lastNotificationUpdateTs = (new Date()).getTime();
                    GAG.PageController.updateNotification(f)
                },error: function(f) {
                    GAG.PageController._isUpdatingNotification = false
                }})
        },markNotificationsAsRead: function() {
            if (GAG.PageController._isMarkingNotificationAsRead) {
                return
            }
            GAG.PageController._isMarkingNotificationAsRead = true;
            var g = GAG.Configs.get("configs.noti.read_state_url");
            var e = GAG.Configs.get("configs.noti.read_state_params");
            var f = b.ajax({url: g,data: e,dataType: "json",type: "POST",success: function(h) {
                    GAG.PageController._isMarkingNotificationAsRead = false;
                    if (h.status == "OK") {
                        GAG.PushController.updateNotificationUnreadCount(0)
                    }
                },error: function(h) {
                    GAG.PageController._isMarkingNotificationAsRead = false
                }})
        },updateNotification: function(g) {
            var e = b(this.selectors.HEADER_NOTIFICATION_CONTAINER);
            e.empty();
            if (g.status == "OK") {
                if (g.items.length > 0) {
                    for (var f = 0; f < g.items.length; f++) {
                        e.append(g.items[f]["message"])
                    }
                    if (GAG.PushController.unreadCount > 20) {
                        b(this.selectors.HEADER_NOTIFICATION_SEE_ALL).text("See " + (GAG.PushController.unreadCount - 20) + " more")
                    } else {
                        b(this.selectors.HEADER_NOTIFICATION_SEE_ALL).text("See all")
                    }
                } else {
                    e.append(g.message)
                }
            } else {
                e.append(g.message)
            }
        }});
    GAG.PushController = b.extend({}, new GAG.Controller(), {DELAY: 1000,INIT_DELAY: 2000,docTitle: a.document.title,_lastBadgetTs: false,_minBadgeInterval: 5000,_regularLongPollingInterval: 180000,_checkUpdateQueueInterval: 1000,_isRequestingUpdate: false,unreadCount: 0,init: function() {
        },onWindowLoad: function() {
            if (!GAG.Configs.get("user.id")) {
                return
            }
            setTimeout(b.proxy(function() {
                this._initPush();
                this._initBadgeUpdate()
            }, this), this.INIT_DELAY)
        },selectors: {NOTIFICATION_UNREAD_COUNT: "#jsid-notification-unread-count"},_log: function(e) {
            if (console && console.log) {
                console.log(e)
            }
        },_pullNotificatons: function(f) {
            var e = b(this.selectors.NOTIFICATION_UNREAD_COUNT);
            if (!e) {
                return
            }
            this.putToUpdateQueue(f)
        },_initPush: function() {
            function f(m, n, i) {
                var l = {type: "noti",message: m,id: n,channel: i};
                GAG.PushController._log(l);
                GAG.PushController._pullNotificatons(l)
            }
            var g = {host: GAG.Configs.get("configs.noti.host"),port: GAG.Configs.get("configs.noti.port"),modes: GAG.Configs.get("configs.noti.modes")};
            if (!g.host || !g.port) {
                return
            }
            var j = new PushStream(g);
            j.onmessage = f;
            var e = GAG.Configs.get("configs.noti.channels");
            if (e instanceof Array) {
                for (var h = 0; h < e.length; h++) {
                    j.addChannel(e[h]);
                    GAG.PushController._log(e[h])
                }
            }
            j.connect()
        },_updateQueue: [],putToUpdateQueue: function(e) {
            this._updateQueue.push(e)
        },getNsReadStateCb: function(e) {
            GAG.PushController._isRequestingUpdate = false;
            GAG.PushController._lastBadgetTs = (new Date()).getTime();
            if (e && e.status == "OK") {
                GAG.PushController.updateNotificationUnreadCount(e.payload.unreadCount)
            } else {
                GAG.PushController._isRequestingUpdate = false
            }
        },_getNsReadState: function() {
            var f = GAG.Configs.get("configs.noti.read_state_url") + "?" + GAG.Configs.get("configs.noti.read_state_params");
            this._isRequestingUpdate = true;
            var e = b.ajax({url: f,type: "GET",dataType: "jsonp",jsonpCallback: "GAG.PushController.getNsReadStateCb",})
        },getNotificationBadge: function() {
            if (this._isRequestingUpdate) {
                return
            }
            return this._getNsReadState()
        },updateNotificationUnreadCount: function(f) {
            var e = b(this.selectors.NOTIFICATION_UNREAD_COUNT);
            if (!e) {
                return
            }
            if (f > 0) {
                GAG.PushController.unreadCount = f;
                e.text(f);
                e.removeClass("hide");
                a.document.title = "(" + f + ") " + GAG.PushController.docTitle
            } else {
                GAG.PushController.unreadCount = 0;
                e.text("0");
                e.addClass("hide");
                a.document.title = GAG.PushController.docTitle
            }
        },checkUpdateQueue: function() {
            if (this._updateQueue.length > 0) {
                this._updateQueue = [];
                this.getNotificationBadge()
            }
        },processUpdateQueue: function() {
            var e = (new Date()).getTime();
            if (!this._lastBadgetTs || e - this._lastBadgetTs >= this._minBadgeInterval) {
                this.checkUpdateQueue()
            }
        },addRegularLongPolling: function() {
            this.putToUpdateQueue({})
        },scheduleRegularLongPolling: function() {
            this.addRegularLongPolling();
            this._regularLongPollingInterval = this._regularLongPollingInterval * 1.5;
            setTimeout("GAG.PushController.scheduleRegularLongPolling();", this._regularLongPollingInterval)
        },_initBadgeUpdate: function() {
            setInterval("GAG.PushController.processUpdateQueue();", this._checkUpdateQueueInterval);
            setTimeout("GAG.PushController.scheduleRegularLongPolling();", this._regularLongPollingInterval)
        },});
    GAG.ProfileController = b.extend({}, new GAG.Controller(), {initShow: "account",init: function() {
            this.bindElements();
            return;
            this.removeAllSelectedBtn();
            this.initShow = b(this.selectors.INIT_SHOW).val();
            if (this.initShow == this.selectors.INIT_SHOW_PROFILE) {
                this.showProfileSection()
            } else {
                if (this.initShow == this.selectors.INIT_SHOW_PWD) {
                    this.showPwdSection()
                } else {
                    if (this.initShow == this.selectors.INIT_SHOW_NOTIFICATION) {
                        this.showNotificationSection()
                    } else {
                        this.showAccountSection()
                    }
                }
            }
        },selectors: {SETTING_SOCIAL_UNLINK_BTNS: ".badge-social-unbind",SETTING_ACCOUNT_BTN: "#jsid-setting-account-btn",SETTING_PWD_BTN: "#jsid-setting-pwd-btn",SETTING_PROFILE_BTN: "#jsid-setting-profile-btn",SETTING_NOTIFICATION_BTN: "#jsid-setting-notification-btn",SETTING_ACCOUNT_SECTION: "#jsid-setting-account",SETTING_PWD_SECTION: "#jsid-setting-pwd",SETTING_PROFILE_SECTION: "#jsid-setting-profile",SETTING_NOTIFICATION_SECTION: "#jsid-setting-notification",SETTING_SECTIONS: ".badge-setting-section",DELETE_MY_ACCOUNT: "#jsid-delete-account-btn",FORM_NAV: ".form-nav",INIT_SHOW: "#jsid-init-show",INIT_SHOW_ACCOUNT: "account",INIT_SHOW_PWD: "pwd",INIT_SHOW_PROFILE: "profile",INIT_SHOW_NOTIFICATION: "notification",PROFILE_AVATAR_IMAGE: "#jsid-profile-avatar",PROFILE_AVATAR_UPLOAD: "input[name=avatar]",PROFILE_DEFAULT_AVATAR: "input[name=default_avatar]",RANDOM_AVATAR_BTN: "#jsid-random-avatar-btn"},showDeleteAccountBtn: function() {
            b(this.selectors.DELETE_MY_ACCOUNT).show()
        },hideDeleteAccountBtn: function() {
            b(this.selectors.DELETE_MY_ACCOUNT).hide()
        },updateInitShow: function(e) {
            b(this.selectors.INIT_SHOW).val(e)
        },highlightBtn: function(e) {
            b(e).addClass("selected")
        },removeAllSelectedBtn: function() {
            b(this.selectors.FORM_NAV + " a").removeClass("selected")
        },showSection: function(e) {
            this.hideAllSection();
            this.removeAllSelectedBtn();
            b(e).removeAttr("style")
        },showAccountSection: function() {
            this.showSection(this.selectors.SETTING_ACCOUNT_SECTION);
            this.highlightBtn(this.selectors.SETTING_ACCOUNT_BTN);
            this.updateInitShow(this.selectors.INIT_SHOW_ACCOUNT);
            this.showDeleteAccountBtn()
        },showPwdSection: function() {
            this.showSection(this.selectors.SETTING_PWD_SECTION);
            this.highlightBtn(this.selectors.SETTING_PWD_BTN);
            this.updateInitShow(this.selectors.INIT_SHOW_PWD);
            this.hideDeleteAccountBtn()
        },showProfileSection: function() {
            this.showSection(this.selectors.SETTING_PROFILE_SECTION);
            this.highlightBtn(this.selectors.SETTING_PROFILE_BTN);
            this.updateInitShow(this.selectors.INIT_SHOW_PROFILE);
            this.hideDeleteAccountBtn()
        },showNotificationSection: function() {
            this.showSection(this.selectors.SETTING_NOTIFICATION_SECTION);
            this.highlightBtn(this.selectors.SETTING_NOTIFICATION_BTN);
            this.updateInitShow(this.selectors.INIT_SHOW_NOTIFICATION);
            this.hideDeleteAccountBtn()
        },hideAllSection: function() {
            b(this.selectors.SETTING_SECTIONS).css("position", "absolute").css("left", -1000)
        },_bindSocialUnlinkButtons: function() {
            b(this.selectors.SETTING_SOCIAL_UNLINK_BTNS).on("click", function(h) {
                var g = b(this);
                var f = g.attr("data-platform");
                b.ajax({url: "/connect/unlink",data: {platform: f},dataType: "json",success: function(e) {
                        if (e && e.okay) {
                            a.location.reload()
                        }
                    },error: function(e) {
                    }})
            })
        },_bindRandomAvatarButton: function() {
            var g = b(this.selectors.PROFILE_AVATAR_IMAGE);
            var e = b(this.selectors.PROFILE_DEFAULT_AVATAR);
            var f = b(this.selectors.RANDOM_AVATAR_BTN);
            b(f).click(b.proxy(function() {
                var j = f.data("path");
                var h = f.data("max");
                var i = Math.floor(Math.random() * h + 1);
                var l = j.replace("%random%", i);
                if (g.attr("src") != l) {
                    g.attr("src", l);
                    e.val(i);
                    var m = b(this.selectors.PROFILE_AVATAR_UPLOAD);
                    m.replaceWith(m.clone())
                } else {
                    f.click()
                }
                return false
            }, this));
            b(document).on("change", this.selectors.PROFILE_AVATAR_UPLOAD, function() {
                e.val("")
            })
        },bindElements: function() {
            this._bindSocialUnlinkButtons();
            this._bindRandomAvatarButton();
            return;
            b(this.selectors.SETTING_ACCOUNT_BTN).on("click", b.proxy(this.showAccountSection, this));
            b(this.selectors.SETTING_PWD_BTN).on("click", b.proxy(this.showPwdSection, this));
            b(this.selectors.SETTING_PROFILE_BTN).on("click", b.proxy(this.showProfileSection, this));
            b(this.selectors.SETTING_NOTIFICATION_BTN).on("click", b.proxy(this.showNotificationSection, this))
        },});
    GAG.OverlayController = b.extend({}, new GAG.Controller(), {_isShown: false,_hideUsingBackground: true,selectors: {OVERLAY: "#overlay-container",OVERLAY_COMPONENT: "section",OVERLAY_CLOSE_BUTTON: ".badge-overlay-close",OVERLAY_COMPONENT_REPORT: ".badge-overlay-report",OVERLAY_COMPONENT_LOGIN: ".badge-overlay-signin",OVERLAY_COMPONENT_SIGNUP_FB: ".badge-overlay-signup-fb",OVERLAY_COMPONENT_SIGNUP_EMAIL: ".badge-overlay-signup-email"},init: function() {
            this.bindOverlayCloseButtons()
        },handlers: {closeButtonClickedHandler: function(e) {
                this.hideOverlay(b(e.currentTarget).closest(this.selectors.OVERLAY_COMPONENT));
                e.preventDefault()
            },overlayBackgroundClickedHandler: function(e) {
                if (this._hideUsingBackground) {
                    this.hideAllOverlay()
                }
            },overlayComponentClickedHandler: function(e) {
                e.stopPropagation()
            }},showOverlay: function(e) {
            this.hideAllOverlay();
            this._isShown = true;
            b(this.selectors.OVERLAY).removeClass("hide");
            b("body").addClass("no-scroll");
            if (typeof e != "undefined") {
                b(e).removeClass("hide")
            }
        },hideOverlay: function(e) {
            this._isShown = false;
            b(this.selectors.OVERLAY).addClass("hide");
            b("body").removeClass("no-scroll");
            if (typeof e != "undefined") {
                b(e).addClass("hide")
            }
            GAG.PageController.resetCustomize()
        },hideAllOverlay: function() {
            this.hideOverlay(b(this.selectors.OVERLAY).children())
        },bindOverlayCloseButtons: function() {
            b(this.selectors.OVERLAY).find(this.selectors.OVERLAY_CLOSE_BUTTON).click(b.proxy(this.handlers.closeButtonClickedHandler, this));
            b(this.selectors.OVERLAY).click(b.proxy(this.handlers.overlayBackgroundClickedHandler, this));
            b(this.selectors.OVERLAY).find(this.selectors.OVERLAY_COMPONENT).click(b.proxy(this.handlers.overlayComponentClickedHandler, this))
        },isInsideOverlay: function(e) {
            return b(e).is(this.selectors.OVERLAY + " *")
        }});
    GAG.KeyboardController = b.extend({}, new GAG.Controller(), (function() {
        var e = {JUMP_PREV: "JUMP_PREV",JUMP_NEXT: "JUMP_NEXT",VOTE_UP: "VOTE_UP",VOTE_DOWN: "VOTE_DOWN",UNVOTE: "UNVOTE",JUMP_COMMENT: "JUMP_COMMENT",_track: function(f) {
                GAG.GA.track("keyboard", f, GAG.Page.getPageKey())
            },_bindJumpPrev: function(f) {
                e.bindAction(f, function() {
                    e._track("prev");
                    if (GAG.Page.isPostPage()) {
                        GAG.PostController.prevEntry()
                    } else {
                        e.jump(e.JUMP_PREV)
                    }
                });
                if (GAG.Page.isPostPage()) {
                    b(document).keydown(function(g) {
                        if (g.keyCode == 37) {
                            GAG.PostController.prevEntry();
                            return false
                        }
                    })
                }
            },_bindJumpNext: function(f) {
                e.bindAction(f, function() {
                    e._track("next");
                    if (GAG.Page.isPostPage()) {
                        GAG.PostController.nextEntry()
                    } else {
                        e.jump(e.JUMP_NEXT)
                    }
                });
                if (GAG.Page.isPostPage()) {
                    b(document).keydown(function(g) {
                        if (g.keyCode == 39) {
                            GAG.PostController.nextEntry();
                            return false
                        }
                    })
                }
            },_bindPostVoteUp: function(f) {
                e.bindAction(f, function() {
                    e._track("upvote");
                    GAG.PostController.upvoteEntry(GAG.ListController.findCurrentlyInFocusEntry())
                })
            },_bindPostVoteDown: function(f) {
                e.bindAction(f, function() {
                    e._track("downvote");
                    GAG.PostController.downvoteEntry(GAG.ListController.findCurrentlyInFocusEntry())
                })
            },_bindPostComment: function(f) {
                e.bindAction(f, function() {
                    e._track("comment");
                    GAG.PostController.commentEntry(GAG.ListController.findCurrentlyInFocusEntry())
                })
            },_bindScrollToTop: function(f) {
                e.bindAction(f, function() {
                    e._track("back-to-top");
                    e.scrollToTop()
                })
            },_bindRandomEntry: function(f) {
                e.bindAction(f, function() {
                    e._track("random");
                    e.randomEntry()
                })
            },_bindPostPlay: function(f) {
                e.bindAction(f, function() {
                    e._track("play");
                    GAG.PostController.playEntry(GAG.ListController.findCurrentlyInFocusEntry())
                })
            },_bindElements: function() {
                e._bindScrollToTop("b");
                e._bindJumpPrev("k");
                e._bindJumpNext("j");
                e._bindRandomEntry("r");
                e._bindPostVoteUp("l");
                e._bindPostVoteDown("h");
                e._bindPostComment("c");
                e._bindPostPlay("p")
            },_getKeyOptions: function() {
                return {type: "keypress",propagate: false,target: document,disable_in_input: true}
            },bindAction: function(f, g) {
                shortcut.add(f, g, e._getKeyOptions())
            },jump: function(f) {
                if (f == e.JUMP_PREV) {
                    GAG.ListController.scrollToPrevEntry()
                } else {
                    GAG.ListController.scrollToNextEntry()
                }
            },scrollToTop: function() {
                GAG.PageController.scrollToTop()
            },randomEntry: function() {
                GAG.Page.load("http://" + GAG.Page.getDomain() + "/random")
            }};
        return {init: function() {
                e._bindElements()
            },jump: e.jump,bindAction: e.bindAction,scrollToTop: e.scrollToTop,randomEntry: e.randomEntry}
    })());
    GAG.AccountController = b.extend({}, new GAG.Controller(), {init: function() {
            this.bindElements();
            this._showCaptcha()
        },selectors: {HEADER_LOGIN_BUTTON: ".badge-login-button",HEADER_SIGNUP_BUTTON: ".badge-signup-button",LOGIN_FORM_NEXT_URL: "#jsid-login-form-next-url",LOGIN_FACEBOOK_CONNECT_BUTTON: ".badge-facebook-connect",LOGIN_GPLUS_CONNECT_BUTTON: ".badge-gplus-connect",SIGNUP_FB: "#signup-fb",SIGNUP_EMAIL: "#signup-email",SIGNUP_EMAIL_LINK: ".badge-signup-email-link",SIGNUP_LOGIN_LINK: ".badge-signup-login-link",SIGNUP_FORM_NEXT_URL: ".badge-signup-form-next-url",DELETE_CONFIRM_FORM: ".badge-delete-confirm-form",SHOW_DELETE_FORM_BTN: "#jsid-show-form-btn",RESET_SUBMIT_BTN: ".badge-reset-submit",RESET_SUBMIT_FROM: "#jsid-form-reset",RESET_NEW_PWD: "#jsid-reset-new-pwd",RESET_RETYPE_NEW_PWD: "#jsid-reset-retype-new-pwd"},bindElements: function() {
            this.bindSignupElements();
            this.bindLoginElements();
            this.bindFacebookConnectElements();
            this.bindGplusConnectElements();
            this.bindResetForm();
            b(this.selectors.SHOW_DELETE_FORM_BTN).on("click", b.proxy(function() {
                b(this.selectors.DELETE_CONFIRM_FORM).removeClass("hide")
            }, this))
        },bindSignupElements: function() {
            var e = this;
            b(this.selectors.HEADER_SIGNUP_BUTTON).on("click", b.proxy(function(f) {
                f.preventDefault();
                this.presentSignupForm()
            }, this));
            b(this.selectors.SIGNUP_EMAIL_LINK).click(b.proxy(function(f) {
                f.preventDefault();
                this.switchToEmailSignup()
            }, this));
            b(this.selectors.SIGNUP_LOGIN_LINK).each(function() {
                if (GAG.OverlayController.isInsideOverlay(b(this))) {
                    b(this).click(b.proxy(function(f) {
                        f.preventDefault();
                        this.presentLoginForm(b(this.selectors.SIGNUP_FORM_NEXT_URL).val())
                    }, e))
                }
            });
            b(this.selectors.SIGNUP_EMAIL).on("submit", b.proxy(function(h) {
                b(".badge-input-tzo").val(this._getTimezoneOffset());
                var j = true;
                try {
                    if (Recaptcha) {
                        var g = Recaptcha.get_challenge();
                        var f = Recaptcha.get_response();
                        b("#recaptcha_challenge").val(g);
                        b("#recaptcha_response").val(f)
                    }
                } catch (i) {
                }
                if (!j) {
                    h.preventDefault();
                    return false
                }
            }, this))
        },bindLoginElements: function() {
            b(this.selectors.HEADER_LOGIN_BUTTON).on("click", b.proxy(function(f) {
                f.preventDefault();
                this.presentLoginForm()
            }, this))
        },bindFacebookConnectElements: function() {
            b(this.selectors.LOGIN_FACEBOOK_CONNECT_BUTTON).on("click", b.proxy(function(h) {
                h.preventDefault();
                var g = b(this.selectors.LOGIN_FORM_NEXT_URL).val();
                var i = {a: false,d: false,lo: false,dl: false};
                var f = JSON.stringify(i);
                b.cookie("auto_log", f, {path: "/"});
                GAG.Facebook.Connect.connect(g)
            }, this))
        },bindGplusConnectElements: function() {
        },bindResetForm: function() {
            b(this.selectors.RESET_SUBMIT_FROM).submit(b.proxy(function(f) {
                if (this.validateReset()) {
                    return true
                }
                return false
            }, this))
        },validateReset: function() {
            var f = b(this.selectors.RESET_NEW_PWD).val();
            var g = b(this.selectors.RESET_RETYPE_NEW_PWD).val();
            if (f != g) {
                b(".badge-error-message").text("Your new password doesn't seem to be matching.").removeClass("hide");
                return false
            }
            var e = GAG.Validator.isValidPassword(f, 6, 30);
            if (e) {
                b(".badge-error-message").text("").addClass("hide")
            } else {
                b(".badge-error-message").text("Invalid password.").removeClass("hide")
            }
            return e
        },_getTimezoneOffset: function() {
            return new Date().getTimezoneOffset() / -60
        },_captchaLoaded: false,_showCaptcha: function() {
            if (!this._captchaLoaded) {
                b("#captchawrapper").show();
                var e = b("#captchadiv").attr("data-apiKey");
                Recaptcha.create(e, "captchadiv", {tabindex: 1,theme: "custom",custom_theme_widget: "recaptcha_widget",lang: "en",custom_translations: {instructions_visual: "Type the two words:"},callback: function() {
                        GAG.AccountController._captchaLoaded = true
                    }})
            }
        },presentLoginForm: function(e) {
            GAG.GA.track("login-signup", "shown", "login-form");
            GAG.OverlayController.showOverlay(GAG.OverlayController.selectors.OVERLAY_COMPONENT_LOGIN);
            b("#jsid-login-email-name").focus();
            if (typeof e != "undefined") {
                b(this.selectors.LOGIN_FORM_NEXT_URL).val(e);
                b(this.selectors.SIGNUP_FORM_NEXT_URL).val(e)
            } else {
                b(this.selectors.LOGIN_FORM_NEXT_URL).val(location.href);
                b(this.selectors.SIGNUP_FORM_NEXT_URL).val(location.href)
            }
        },presentSignupForm: function(e) {
            GAG.GA.track("login-signup", "shown", "signup-form");
            GAG.OverlayController.showOverlay(GAG.OverlayController.selectors.OVERLAY_COMPONENT_SIGNUP_FB);
            if (typeof e != "undefined") {
                b(this.selectors.LOGIN_FORM_NEXT_URL).val(e);
                b(this.selectors.SIGNUP_FORM_NEXT_URL).val(e)
            } else {
                b(this.selectors.LOGIN_FORM_NEXT_URL).val(location.href);
                b(this.selectors.SIGNUP_FORM_NEXT_URL).val(location.href)
            }
            this.switchToFacebookSignup()
        },switchToEmailSignup: function() {
            GAG.GA.track("login-signup", "shown", "email-signup-form");
            b(this.selectors.SIGNUP_FB).addClass("hide");
            b(this.selectors.SIGNUP_EMAIL).removeClass("hide")
        },switchToFacebookSignup: function() {
            b(this.selectors.SIGNUP_EMAIL).addClass("hide");
            b(this.selectors.SIGNUP_FB).removeClass("hide")
        },setSafeMode: function(f, g) {
            if (typeof g == "undefined") {
                g = ""
            }
            var e = "/profile/safe-browse?enable=" + f + "&url=" + encodeURIComponent(g);
            a.location = e
        }});
    GAG.UploadController = b.extend({}, new GAG.Controller(), {TITLE_LENGTH_WARNING_THRESHOLD: 20,init: function() {
            this._bindElements()
        },selectors: {UPLOAD_URL_BTN: "#jsid-upload-url-btn",UPLOAD_FILE_BTN: "#jsid-upload-file-btn",UPLOAD_URL_INPUT: "#jsid-upload-url-input",UPLOAD_FILE_INPUT: "#jsid-upload-file-input",UPLOAD_CHAR_COUNT: "#jsid-char-count",UPLOAD_TITLE_INPUT: "#jsid-upload-title",UPLOAD_SOURCE_CHECKBOX: "#jsid-source-checkbox",UPLOAD_SOURCE_CHECKBOX_LABEL: "#jsid-source-checkbox-label",UPLOAD_SOURCE_INPUT: "#jsid-source-input",UPLOAD_SUBMIT_BTN: "#jsid-submit-btn",UPLOAD_DISABLE_MASK: "#jsid-disable-mask",UPLOAD_CONTENT_ERROR_LABEL: "#jsid-upload-content-error",UPLOAD_TITLE_ERROR_LABEL: "#jsid-upload-title-error",UPLOAD_ERROR_LABEL: "#jsid-upload-error"},css: {METHOD_SELECTED: "upload-selected",TITLE_WARNING: "warn"},_resetElement: function(e) {
            e.wrap("<form>").closest("form").get(0).reset();
            e.unwrap()
        },_selectFileInput: function() {
            b(this.selectors.UPLOAD_URL_INPUT).addClass("hide").val("");
            b(this.selectors.UPLOAD_FILE_INPUT).removeClass("hide");
            b(this.selectors.UPLOAD_URL_BTN).removeClass(this.css.METHOD_SELECTED);
            b(this.selectors.UPLOAD_FILE_BTN).addClass(this.css.METHOD_SELECTED)
        },_selectUrlInput: function() {
            var e = b(this.selectors.UPLOAD_FILE_INPUT).addClass("hide");
            this._resetElement(e);
            b(this.selectors.UPLOAD_URL_INPUT).removeClass("hide");
            b(this.selectors.UPLOAD_FILE_BTN).removeClass(this.css.METHOD_SELECTED);
            b(this.selectors.UPLOAD_URL_BTN).addClass(this.css.METHOD_SELECTED)
        },_setCharCount: function(j) {
            var i = b(j.currentTarget);
            var f = parseInt(i.data("maxlength"), 10);
            var g = i.val().length;
            var l = f - g;
            var h = b(this.selectors.UPLOAD_CHAR_COUNT).text(l);
            if (l <= this.TITLE_LENGTH_WARNING_THRESHOLD) {
                h.addClass(this.css.TITLE_WARNING)
            } else {
                h.removeClass(this.css.TITLE_WARNING)
            }
        },_updateSourceFields: function(h) {
            var g = b(this.selectors.UPLOAD_SOURCE_CHECKBOX);
            var f = b(this.selectors.UPLOAD_SOURCE_INPUT);
            if (g.is(":checked")) {
                f.removeClass("hide")
            } else {
                f.addClass("hide")
            }
        },_getContentError: function() {
            var e = b(this.selectors.UPLOAD_URL_INPUT).val();
            var f = b(this.selectors.UPLOAD_FILE_INPUT + " input").val();
            if (!e && !f) {
                return "Please select a file or paste an image URL."
            }
            if (false) {
                if (e) {
                    if (!this._isValidImageUrl(e)) {
                        return "Unsupported image type."
                    }
                }
                if ((e && !this._isValidImageExtension(e)) || (f && !this._isValidImageExtension(f))) {
                    return "Unsupported image type."
                }
            }
        },_getTitleError: function() {
            var g = b(this.selectors.UPLOAD_TITLE_INPUT).val();
            var f = 6;
            var e = b(this.selectors.UPLOAD_TITLE_INPUT).data("maxlength");
            if (!g || g.length < f) {
                return "Your title doesn't look funny enough. Be creative!"
            } else {
                if (g.length > e) {
                    return "Your title is a bit long. Be concise!"
                }
            }
        },_isValidImageUrl: function(e) {
            var f = /^http(s?):\/\//i;
            return e.toLowerCase().match(f)
        },_isValidImageExtension: function(f) {
            f += "";
            var g = f.split(".").pop();
            var e = /(jpeg|jpg|gif|png)/i;
            return g.match(e)
        },validateForm: function() {
            var j = this._getContentError();
            var h = this._getTitleError();
            var f = true;
            var i = b(this.selectors.UPLOAD_CONTENT_ERROR_LABEL);
            var g = b(this.selectors.UPLOAD_TITLE_ERROR_LABEL);
            if (j) {
                i.removeClass("hide").text(j);
                f = false
            } else {
                i.addClass("hide").text("")
            }
            if (h) {
                g.removeClass("hide").text(h);
                f = false
            } else {
                g.addClass("hide").text("")
            }
            b(this.selectors.UPLOAD_ERROR_LABEL).addClass("hide").text("");
            if (f) {
                var e = {className: "upload-spinner",top: "200px",left: "205px"};
                GAG.PageController.loadSpinner("spinner-here", e);
                b(this.selectors.UPLOAD_SUBMIT_BTN).val("Uploading...");
                b(this.selectors.UPLOAD_DISABLE_MASK).addClass("disabled");
                b(GAG.OverlayController.selectors.OVERLAY).unbind("click")
            }
            return f
        },_pad: function(f, e) {
            if (e == undefined) {
                e = "0"
            }
            return f < 10 ? e + "" + f : f
        },_convertTime: function(l) {
            var j = 0;
            var g = 0;
            var e = 0;
            var f = 0;
            if (l < 0) {
                l = 0
            }
            j = parseInt(l / 86400);
            l -= j * 86400;
            g = parseInt(l / 3600);
            l -= g * 3600;
            e = parseInt(l / 60);
            l -= e * 60;
            f = l;
            var i = "";
            if (j > 0) {
                i += this._pad(j) + ":"
            }
            i += this._pad(g) + ":";
            i += this._pad(e) + ":";
            i += this._pad(f);
            return i
        },_updateDisplay: function(g) {
            var h = g.data("timestamp");
            var f = Math.round((new Date()).getTime() / 1000);
            var i = g.data("start");
            if (i == null) {
                i = f;
                g.data("start", i)
            }
            var e = f - i;
            g.text(this._convertTime(h - e))
        },_updateAll: function() {
            b(".badge-countdown").each(function() {
                GAG.UploadController._updateDisplay(b(this))
            })
        },_bindElements: function() {
            var e = b(".badge-countdown");
            if (e.length > 0) {
                GAG.UploadController._updateAll();
                setInterval("GAG.UploadController._updateAll();", 1000)
            }
            b(this.selectors.UPLOAD_URL_BTN).on("click", b.proxy(function(f) {
                f.preventDefault();
                this._selectUrlInput()
            }, this));
            b(this.selectors.UPLOAD_FILE_BTN).on("click", b.proxy(function(f) {
                f.preventDefault();
                this._selectFileInput()
            }, this));
            b(this.selectors.UPLOAD_TITLE_INPUT).on("keydown", b.proxy(function(f) {
                setTimeout(b.proxy(this._setCharCount, this, f), 50)
            }, this));
            b(this.selectors.UPLOAD_SOURCE_CHECKBOX).on("change", b.proxy(this._updateSourceFields, this))
        },});
    GAG.InviteController = b.extend({}, new GAG.Controller(), {init: function() {
            if (!GAG.Page.isInviteFacebookPage()) {
                return
            }
            this._bindElements();
            this._getFbFriendInviteList();
            this._filterFriendName()
        },selectors: {FB_FRIEND_LIST: "#jsid-fb-friend-list",FB_FRIEND_SEARCH_BOX: "#jsid-fb-friend-search-box",FB_SEND_INVITE_BTN: "#jsid-btn-fb-invite",NEXT_BTN: "#jsid-btn-next"},_bindElements: function() {
            this._bindNextBtn()
        },_bindNextBtn: function() {
            b(GAG.InviteController.selectors.NEXT_BTN).click(function(g) {
                g.preventDefault();
                var f = decodeURIComponent(GAG.Utils.getUrlParam("next"));
                f = "" + f;
                if (f.indexOf("http") !== -1) {
                    a.location.href = f
                } else {
                    location.href = "http://" + GAG.Page.getDomain() + ((f != "null") ? f : "/")
                }
            })
        },_filterFriendName: function() {
            GAG.Utils.textSearch(GAG.InviteController.selectors.FB_FRIEND_SEARCH_BOX, GAG.InviteController.selectors.FB_FRIEND_LIST + " li", "p", {highlight: true})
        },_renderFbFriendInviteList: function(f) {
            var e = b(GAG.InviteController.selectors.FB_FRIEND_LIST);
            if (f.error) {
            } else {
                if (f.data) {
                    b.each(f.data, function(m, l) {
                        var n = GAG.Facebook.getProfilePic(l.id);
                        var j = b("<img>").attr("src", n).attr("alt", l.name);
                        var o = b("<p>").text(l.name);
                        var h = b('<a class="button" href="#">invite</a>');
                        var g = b("<li>");
                        g.append(j);
                        g.append(o);
                        g.append(h);
                        e.append(g);
                        h.click(function(i) {
                            i.preventDefault();
                            GAG.Facebook.openSendDialog(l.id, "Join me on 9GAG!", "http://9gag.com", null, null)
                        })
                    })
                }
            }
        },_getFbFriendInviteList: function() {
            GAG.Facebook.addGetFriendsCallback(this._renderFbFriendInviteList)
        }});
    GAG.App = (function() {
        var e = {_data: {},_models: [],_controllers: [],init: function() {
                var f = e;
                b(document).ready(function() {
                    f._onDomReady()
                });
                b(a).on("load", function() {
                    f._onWindowLoad()
                });
                b(a).on("scroll", function(g) {
                    f._runOnControllers("onScroll")
                });
                b(a).on("resize", function(g) {
                    f._runOnControllers("onResize")
                })
            },_onDomReady: function() {
                e._runOnModels("init");
                e._runOnControllers("init")
            },_onWindowLoad: function() {
                e._runOnModels("onWindowLoad");
                e._runOnControllers("onWindowLoad")
            },_runOnObjects: function(g, h) {
                if (!g instanceof Array) {
                    return
                }
                for (var f = 0; f < g.length; f++) {
                    if (g[f][h] && typeof g[f][h] == "function") {
                        g[f][h]()
                    }
                }
            },_runOnModels: function(f) {
                e._runOnObjects(e._models, f)
            },_runOnControllers: function(f) {
                e._runOnObjects(e._controllers, f)
            },addModel: function(g) {
                if (g instanceof Array) {
                    for (var f = 0; f < g.length; f++) {
                        e._models.push(g[f])
                    }
                } else {
                    e._models.push(g)
                }
                return this
            },addController: function(g) {
                if (g instanceof Array) {
                    for (var f = 0; f < g.length; f++) {
                        e._controllers.push(g[f])
                    }
                } else {
                    e._controllers.push(g)
                }
                return this
            },setData: function(f, g) {
                e._data[f] = g
            },_scriptMap: {facebook: "//connect.facebook.net/en_US/all.js",twitter: "//platform.twitter.com/widgets.js","client:plusone": "https://apis.google.com/js/client:plusone.js?onload=gplusRender",pinterest: "//assets.pinterest.com/js/pinit.js",ga: ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js",quantserve: (document.location.protocol == "https:" ? "https://secure" : "http://edge") + ".quantserve.com/quant.js"},_loadAsyncScript: function(f) {
                (function() {
                    var h = document.createElement("script");
                    h.type = "text/javascript";
                    h.async = true;
                    h.src = f;
                    var g = document.getElementsByTagName("script")[0];
                    g.parentNode.insertBefore(h, g)
                })()
            },loadAsynScripts: function(f) {
                for (var g = 0; g < f.length; g++) {
                    if (e._scriptMap[f[g]]) {
                        e._loadAsyncScript(e._scriptMap[f[g]])
                    }
                }
            },loadConfigs: function(f) {
                GAG.Configs.load(f);
                return this
            }};
        return {init: e.init,loadConfigs: e.loadConfigs,loadAsynScripts: e.loadAsynScripts,addModel: e.addModel,addController: e.addController}
    })();
    var d = [GAG.User, GAG.Vote, GAG.Configs, GAG.Page, GAG.Facebook, GAG.GPlus, GAG.Track];
    var c = [GAG.ProfileController, GAG.ListController, GAG.OverlayController, GAG.FacebookController, GAG.GPlusController, GAG.ShareController, GAG.PostController, GAG.VoteController, GAG.PageController, GAG.KeyboardController, GAG.HeadbarController, GAG.AccountController, GAG.InviteController, GAG.ListScrollingController, GAG.UploadController, GAG.PushController];
    GAG.App.addModel(d).addController(c).init()
})(jQuery, window);
